Find Integer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 6597 Accepted Submission(s): 1852
Special Judge
Problem Description
people in USSS love math very much, and there is a famous math problem .
give you two integers n,a,you are required to find 2 integers b,c such that an+bn=cn.
Input
one line contains one integer T;(1≤T≤1000000)
next T lines contains two integers n,a;(0≤n≤1000,000,000,3≤a≤40000)
Output
print two integers b,c if b,c exits;(1≤b,c≤1000,000,000);
else print two integers -1 -1 instead.
Sample Input
1
2 3
Sample Output
4 5
题意:现有一个式子 a^n + b^n = c^n 给一个n和a, 求出b, c.
题解:根据费马大定理,我们知道了,当n>2是,为无解,另n=0,也无解,因此n=1,
n=2时:即在一组勾股数中,当最小边为奇数时,它的平方刚好等于另外两个连续的正整数之和.勾股数公式一:(2n+1,2n^2+2n,2n^2+2n+1)(n为正整数)
即在一组勾股数中,当最小边为偶数时,它的平方刚好等于两个连续整数之和的二倍,勾股数公式二:(2n,n^2-1,n^2+1)(n≥2且n为正整数)
当n>=3, a^n + b^n = c^n 没有正整数解。(费马大定理)
#include<bits/stdc++.h>
#define LL long long
using namespace std;
///2n+1,2n2+2n,2n2+2n+1
/// 2n,n2-1,n2+1
int main() {
int T, n, a;
scanf("%d", &T);
while(T--) {
int k, b, c;
scanf("%d%d", &n, &a);
if(n == 0 || n > 2)printf("-1 -1\n");
else {
if(n == 1) printf("1 %d\n", a + 1);
else if(n == 2){
if(a % 2 == 1) {
k = (a-1)/2;
b = 2*k*k+2*k;
c = b + 1;
}
else {
k = a/2;
b = k*k-1;
c = k*k+1;
}
printf("%d %d\n", b, c);
}
}
}
return 0;
}