Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)
2024-08-24 10:36:52
题目链接:
https://codeforces.com/contest/707/problem/C
题目:
题意:
告诉你直角三角形的一条边,要你输出另外两条边。
思路:
我们容易发现除2外的所有素数x作为直角边,那么另外两条边的长度一定为(x * x - 1)/2和(x * x + 1)/2,因此对于每个数我们只需要找到n的最小素因子(除2外)即可,需要额外处理一下2的幂次。
代码实现如下:
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-;
const int mod = ;
const int maxn = 2e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; LL t; int main(){
scanf("%lld", &t);
if(t <= ) {
puts("-1");
return ;
}
for(int i = ; i <= sqrt(t); i++) {
if(t % i == ) {
LL tmp = t / i;
LL x = 1LL * i * i;
if(x & ) {
printf("%lld %lld\n", (1LL * i * i - ) / * tmp, (1LL * i * i + ) / * tmp);
return ;
}
}
}
LL num = ;
while(t % == ) {
num = num * ;
t /= ;
}
if(t == ) {
t = ;
num /= ;
printf("%lld %lld\n", * num, * num);
} else {
printf("%lld %lld\n", (t * t - ) / * num, (t * t + ) / * num);
}
return ;
}
最新文章
- [iOS UI进阶 - 2.3] 彩票Demo v1.3
- USB Key插入和移除监控
- 第一个Xcode项目 - 代码修改布局约束
- VS 2012 插件卸载(删除自己安装的插件)
- AFNetwork学习(二)——GET/POST请求
- 使用cocos2d 2.1制作一条河游戏(4): 主要的游戏逻辑BaseLayer设计
- match in shell scripts
- hibernate子查询
- 人生苦短,我用Python
- String 类问题发现与解决
- 分页复用代码【Page类、JSP显示页面】
- android DecorView深入理解
- chrome调试vue.js的插件:vue.js devtools
- pwnable.kr-bof-witeup
- 算法学习笔记:knn理论介绍
- Day29作业及默写
- 简单利用gulp-babel搭建es6转es5环境
- (转)手机的AP和BP是什么?
- Xposed模块开发教程
- 面向对象SOLID设计原则之Open-Closed原则
热门文章
- mysql 函数示例(转)
- yii2微博第三方登录
- struts 跳转的四种常用类型
- There is no getter for property named &#39;notice&#39; in &#39;class com.game.domain.Notices&#39;
- java的object类函数详解
- ORA-01034和ORA-27101的解决方法
- MT【130】Heilbronn问题
- 【UOJ#80】二分图最大权匹配(KM)
- 【转】关于在linux下清屏的几种技巧
- myeclipse2015修改web项目部署名