本文主要是介绍Codeforces Round #368 (Div. 2)(C. Pythagorean Triples 勾股数规律),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接
给出一个数,输出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;
}
这篇关于Codeforces Round #368 (Div. 2)(C. Pythagorean Triples 勾股数规律)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!