HDU - 6441(费马大定理)
链接:HDU - 6441
题意:已知 n,a,求 b,c 使 a^n + b^n = c^n 成立。
题解:费马大定理
1.a^n + b^n = c^n,当 n > 2 时无解;
2.
当 a 为奇数
a = 2 * k + 1;
c = k ^ 2 + (k + 1) ^ 2;
b = c - 1;
当 a 为偶数
a = 2 * k + 2;
c = 1 + (k + 1) ^ 2;
b = c - 2;
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-6; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 1e5 + 10; long long n, a, b, c; int main() { int T; scanf("%d", &T); while(T--){ scanf("%lld%lld", &n, &a); if(n == 0 || n > 2){ puts("-1 -1"); continue; } if(n == 1){ printf("%lld %lld\n", a, a<<1); continue; } if(a & 1LL){ long long k = a / 2; c = k * k + (k + 1) * (k + 1); b = c - 1; } else{ long long k = a / 2 - 1; c = 1 + (k + 1) * (k + 1); b = c - 2; } printf("%lld %lld\n", b, c); } return 0; }