HDU 6441 Find Integer

版权声明:版权归Ordinarv所有 https://blog.csdn.net/ordinarv/article/details/82107788

题目大意

已知a,n求a^n+b^n=c^n,根据费马大定理可知,当n>2时无解  n==0易知无解。

n=1,b=1,c=a+b;

n=2,即为勾股数。


Ps

cin wa,可采用打表,或用scanf

AC code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int INF=0x3f3f3f3f;
int main() {
	int t,n,a;
	ll b,c,tem;
	scanf("%d",&t);
	while(t--) {
		scanf("%d%d",&n,&a);
		if(n<1||n>2) printf("-1 -1\n");
		else if(n==1) printf("%d %lld\n",1,a+1);
		else {
			tem=a/2;
			if(a%2==0) {
				b=tem*tem;
				printf("%lld %lld\n",b-1,b+1);
			} else {
				b=(tem)*(tem)*2+2*tem;
				printf("%lld %lld\n",b,b+1);
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ordinarv/article/details/82107788
今日推荐