Find Integer(大费马定理&&勾股定理)

费马大定理

当整数n >2时,关于x, y, z的方程 x^n + y^n = z^n 没有正整数解。故,只考虑n=1, n=2, n=0

当n=0时,肯定不成立;

当n=1时,该题是特判,所以输出一组就好了;

当n=2时,勾股数

【代码】

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,a;
		scanf("%d%d",&n,&a);
		if(n>2||n==0)printf("-1 -1\n");
		else if(n==1)//输出一组就好 
			printf("%d %d\n",1,1+a);
		else{
			int k=a/2;
			if(a&1)//a为大于1的奇数 
				printf("%d %d\n",2*k*k+2*k,2*k*k+2*k+1);
			else //a为大于4的偶数2n 
				printf("%d %d\n",k*k-1,k*k+1);
		}
	}
	return 0; 
 } 

猜你喜欢

转载自blog.csdn.net/qq_38735931/article/details/82078590
今日推荐