题目链接:

  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 ;
}

最新文章

  1. [iOS UI进阶 - 2.3] 彩票Demo v1.3
  2. USB Key插入和移除监控
  3. 第一个Xcode项目 - 代码修改布局约束
  4. VS 2012 插件卸载(删除自己安装的插件)
  5. AFNetwork学习(二)——GET/POST请求
  6. 使用cocos2d 2.1制作一条河游戏(4): 主要的游戏逻辑BaseLayer设计
  7. match in shell scripts
  8. hibernate子查询
  9. 人生苦短,我用Python
  10. String 类问题发现与解决
  11. 分页复用代码【Page类、JSP显示页面】
  12. android DecorView深入理解
  13. chrome调试vue.js的插件:vue.js devtools
  14. pwnable.kr-bof-witeup
  15. 算法学习笔记:knn理论介绍
  16. Day29作业及默写
  17. 简单利用gulp-babel搭建es6转es5环境
  18. (转)手机的AP和BP是什么?
  19. Xposed模块开发教程
  20. 面向对象SOLID设计原则之Open-Closed原则

热门文章

  1. mysql 函数示例(转)
  2. yii2微博第三方登录
  3. struts 跳转的四种常用类型
  4. There is no getter for property named &#39;notice&#39; in &#39;class com.game.domain.Notices&#39;
  5. java的object类函数详解
  6. ORA-01034和ORA-27101的解决方法
  7. MT【130】Heilbronn问题
  8. 【UOJ#80】二分图最大权匹配(KM)
  9. 【转】关于在linux下清屏的几种技巧
  10. myeclipse2015修改web项目部署名