[Codeforces #368 (Div. 2) Pythagorean Triples] 數學：勾股數

a,b,c互質的勾股數組的方法
(1)當a為大於1的奇數2n+1時，b=2n^2+2n, c=2n^2+2n+1。

n=1時(a,b,c)=(3,4,5)
n=2時(a,b,c)=(5,12,13)
n=3時(a,b,c)=(7,24,25)[1]
… …

(2)當a為大於等於4(注意：百度百科這個地方錯了… )的偶數2n時，b=n^2-1, c=n^2+1。

n=3時(a,b,c)=(6,8,10)
n=4時(a,b,c)=(8,15,17)
n=5時(a,b,c)=(10,24,26)
n=6時(a,b,c)=(12,35,37)[1]
… …

n=2時(a,b,c)=(8,15,17)
n=3時(a,b,c)=(12,35,37)
n=4時(a,b,c)=(16,63,65)[1]
… …

``````#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
#define fst first
#define snd second

typedef __int64 LL;
typedef unsigned __int64 ULL;
//typedef long long LL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f;
const int MAXN = 1000 + 5;

ULL N, M, K, X;
int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif // ONLINE_JUDGE
while (~scanf ("%I64u", &N) ) {
X = N >> 1;
if (N & 1) {
if (N <= 1) {
printf ("-1\n");
continue;
}
M = ( (X * X + X) << 1);
K = ( (X * X + X) << 1) | 1;
} else {
if (N < 4) {
printf ("-1\n");
continue;
}
M = X * X - 1;
K = X * X + 1;
}
printf ("%I64u %I64u\n", M, K);
}
return 0;
}``````