https://vjudge.net/problem/HDU-6441
题意:
给出n和a求b, c满足a^n + b^n = c^n
ac:
简单的费马大定理+勾股数
费马大定理:当整数n >2时,关于x, y, z的方程 x^n + y^n = z^n 没有正整数解
勾股数:
a^2+b^2=c^2,已知a,求b和c
当 a 为奇数时,则 a = 2 * x + 1 ,解得 x 的值,则 b = 2 * x * ( x + 1 ),c = 2 * x * ( x + 1 ) + 1;
当 a 为偶数时,则 a 可能等于 p * ( 2 * x + 1 ),也可能等于 2 * x * ( x + 1 )
=>2 * x + 1,2 * x* ( x+ 1 ),2 *x * ( x+ 1 ) + 1( x 为正整数 )
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
long long a,b,c,n,x;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&n,&a);
if(n>2)
printf("-1 -1\n");
else if(n==2)
{
if(a%2==0)
{
x=a/2;
printf("%lld %lld\n",x*x-1,x*x+1);
}
else {
x=(a-1)/2;
printf("%lld %lld\n",2*x+2*x*x,2*x+2*x*x+1);
}
}
else if(n==1)
printf("1 %lld\n",1+a);
else if(n==0)
printf("-1 -1\n");
}
return 0;
}