codeforces.com/707/C C. Pythagorean Triples 勾股数
来源:互联网 发布:excel2007表格数据总计 编辑:程序博客网 时间:2024/06/07 10:58
又是个数学问题,我也是醉了
这个问题是关于勾股数的,知一求二
当 a 为大于 1 的奇数 2 * n+1 时, b = 2 * n * n + 2 * n, c = 2 * n * n + 2 * n + 1.
当 a 为大于 4 的偶数 2 * n 时,b = n * n - 1, c = n * n + 1.
然后不满足上述构造方法的数 1, 2, 4直接特判就好.
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<string>#include<vector>#include<stack>#include<set>#include<map>#include<queue>#include<algorithm>using namespace std;int main(){long long a;scanf("%lld",&a);long long b,c;long long n;if(a%2==1&&a>1){n=(a-1)/2;b=n*n*2+2*n;c=b+1;}else if(a%2==0&&a>4){n=a/2;b=n*n-1;c=b+2;}else{if(a==4){b=3;c=5;}}if(a==1||a==2){printf("-1\n");}else{printf("%lld %lld\n",b,c);} return 0;}
0 0
- codeforces.com/707/C C. Pythagorean Triples 勾股数
- codeforces 707 c Pythagorean Triples 数论+勾股数
- codeforces 707C - Pythagorean Triples
- codeforces 707C Pythagorean Triples
- 【codeforces 707C Pythagorean Triples】
- codeforces--707C. Pythagorean Triples
- CodeForces 707C-Pythagorean Triples
- codeforces 707 C Pythagorean Triples【数学】
- Codeforces 707C Pythagorean Triples(数学)
- Codeforces Problem 707C Pythagorean Triples(数学)
- codeforces 707C Pythagorean Triples(数学)
- CodeForces 707C Pythagorean Triples(数学题)
- CodeForces 707C Pythagorean Triples(数学 构造)
- codeforces 707-C. Pythagorean Triples(数学)
- [codeforces] C - Pythagorean Triples 数学
- 【Codeforces Round #368 (Div. 2)】Codeforces 707C Pythagorean Triples
- #368 C. Pythagorean Triples 勾股数
- Codeforces #368(Div.2)C. Pythagorean Triples【勾股数】
- linux c中相关时间函数的总结
- 不用循环求1+2+3...+n之和的多种求法
- 文章标题
- python的json模块
- java-durid、mybatis、spring 整合基于 AbstractRoutingDataSource 的多数据源读写分离配置
- codeforces.com/707/C C. Pythagorean Triples 勾股数
- [Lpp]MySql数据库系统操作
- github个人博客(hexo+next)
- SLF 的锁屏密码
- 【腾讯云的1001种玩法】LAMP架构实现动态网站论坛系统
- 程序猿必修课之数据结构(一)数据结构基本概念和术语
- [Lpp]MySQL服务器的用户权限管理
- 关于/var/run/docker.sock
- Javascript学习-简单测试环境