Codeforces Round #368 (Div. 2)(C. Pythagorean Triples 勾股数规律)
来源:互联网 发布:wps数据透视表怎么排序 编辑:程序博客网 时间:2024/05/21 09:33
题目链接
给出一个数,输出2个数,使得这三个数是勾股数
形如2n,n^2-1,n^2+1可以组合成勾股数,这是偶数的情况
奇数的时候看个例子
3, 4 , 5 | 4 = (1+3) * 1
5,12,13 | 12 = (1+5)*2
7,24,25 | 24 = (1+7)*3
9,40,41 | 40 = (1+9)*4
…
第二列数就是第一列数在以3为首项的等差数列中的位置*(该数+1)
#include<bits/stdc++.h>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define fastIO ios::sync_with_stdio(false);cin.tie(0);#define LL long long#define pb push_back#define gcd __gcd#define For(i,j,k) for(int i=(j);i<k;i++)#define lowbit(i) (i&(-i))#define _(x) printf("%d\n",x)const int maxn = 3e6+10;const int inf = 1 << 28;LL mx = 1e18;bool flag = false;void out(LL a,LL b) { if(a>mx||b>mx||a<=0||b<=0) { //printf("-1\n"); return; } else { printf("%lld %lld\n",a,b); flag = true; }}void work(LL n) { flag = false; if(n%3==0) { out(n/3*4,n/3*5); } if(flag) return ; if(n%4==0) { out(n/4*3,n/4*5); } if(flag) return ; if(n%5==0) { out(n/5*3,n/5*4); } if(flag) return ; if(n%2==1) { LL t = (n-1)/2; LL a = t*(n+1); LL b = a+1; out(a,b); } if(flag) return ; if(n%2==0){ LL t = n/2; LL a = t*t-1; LL b = t*t+1; out(a,b); } if(flag) return ; puts("-1");}int main() { LL n; scanf("%lld",&n); work(n); return 0;}
0 0
- Codeforces Round #368 (Div. 2)(C. Pythagorean Triples 勾股数规律)
- Codeforces 707 C. Pythagorean Triples(找规律)——Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples (本原勾股数)
- Codeforces Round #368 (Div. 2) -- C. Pythagorean Triples (数学公式)
- 【Codeforces Round #368 (Div. 2)】Codeforces 707C Pythagorean Triples
- Codeforces #368(Div.2)C. Pythagorean Triples【勾股数】
- Codeforces Round #368 (Div. 2) C Pythagorean Triples(构造勾股数)
- Codeforces Round #368 (Div. 2) Pythagorean Triples
- Codeforces Round #368 (Div. 2) Pythagorean Triples
- Codeforces Round #368 (Div. 2)C Pythagorean Triples
- Codeforces Round #368 (Div. 2)-C. Pythagorean Triples
- Codeforces Round #368 (Div. 2)C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) -C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) problem: (C) Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学构造)
- error C2668: “swap”: 对重载函数的调用不明确
- 出墙报
- html注意点
- [转]putty颜色
- this指针in C++
- Codeforces Round #368 (Div. 2)(C. Pythagorean Triples 勾股数规律)
- KnockoutJs (三)为Json数据添加监控属性(方法)
- MySql(10)------mysql运算符大全
- 留着看看
- 使用Notepad++搭建任意语言开发环境
- 坐标系及欧拉角
- Dave3入门_构建工程
- 【模拟】Codeforces 707A Brain's Photos
- 进程总结