题目链接:

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

Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)的更多相关文章

  1. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  2. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  3. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  4. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  5. Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

    C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...

  6. Codeforces Round #368 (Div. 2) C

    Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...

  7. Codeforces Round #368 (Div. 2)A B C 水 图 数学

    A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #368 (Div. 2) A , B , C

    A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #368 (Div. 2) D. Persistent Bookcase

    Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...

随机推荐

  1. [知乎]SSD的延迟

    以及一些SSD的性能数据

  2. p2 碰撞

    P2可以实现物体碰撞模拟,同时在碰撞过程中派发一些事件实现碰撞检测,将碰撞信息及时反馈,以添加相应的特效. P2中,当两个刚体的最小包围盒AABB发生重叠,碰撞就开始了:然后刚体的形状发生重叠,同时P ...

  3. javascript定时保存表单数据的代码

    (忘记是不是两家邮箱都有这个功能). 那这个功能是怎么做的呢? 定时,我们知道怎么弄,但保存呢?也许我们会通过隐藏域等手段来存放数据.但是,这个却有个缺点:那就是刷新页面后,数据将会丢失. 而此时,就 ...

  4. 打豪车应用:uber详细攻略(附100元优惠码)

    在嘀嘀打车和快的打车交战热闹的时候,美国的打车应用uber进入中国.与在美国以个人司机注册做 Uber 司机为主的模式不同,Uber 在中国采用与租车公司合作.由租车公司提供车辆和司机的模式,同时中文 ...

  5. Android CollapsingToolbarLayout

    第一次看到这种用户体验是在Google Play Store App的应用详情的Activity中. 大的Banner图,能第一时间吸引用户的眼球,用不一样的Banner大图更具个性化的展示内容.图总 ...

  6. php 关于文件的一些封装好的函数

    <?php //Bytes/Kb/MB/GB/TB/EB /** * 转换字节大小 * @param number $size * @return number */ function tran ...

  7. Alternate Task UVA - 11728 (暴力。。分解质因子)

    题意: 输入一个正整数S,(S  <= 1000)求一个最大的正整数N,使得N的所有正因子之和为S. 解析: ..求1000以内的所有数的正因子和 ...输出.. #include <io ...

  8. [BZOJ1559]密码 AC自动机+状压

    问题 K: [JSOI2009]密码 时间限制: 1 Sec  内存限制: 64 MB 题目描述 众所周知,密码在信息领域起到了不可估量的作用.对于普通的登陆口令,唯一的破解 方法就是暴力破解一逐个尝 ...

  9. 【原创】centos6创建sftp账号,并设置权限和目录

    网上找了个教程,折腾好长时间都不行,最后往死里整,终于弄好了,记录一下. 系统环境:Centos6.9 64bit 完美解决: Permission denied (publickey,gssapi- ...

  10. Vue 中使用UEditor富文本编辑器-亲测可用-vue-ueditor-wrap

    其中UEditor中也存在不少错误,再引用过程中. 但是UEditor相对还是比较好用的一个富文本编辑器. vue-ueditor-wrap说明 Vue + UEditor + v-model 双向绑 ...