hdu6441 Find Integer 求勾股数 费马大定理

题目传送门

题目大意:

给出a和n,求满足a^{^{n}}+b^{n}=c^{n}的b和c。

思路:

数论题目,没什么好说的。

根据费马大定理,当n>2时不存在正整数解。

当n=0或者1时特判一下就可以了,也就是此时变成了一个求勾股数的问题。

勾股数的规律

1. 直角三角形短直角边为奇数,另一条直角边与斜边是两个连续自然数,则两边之和是短直角边的平方。

a=2*n+1,b=2*n*(n+1),c=2*n*(n+1)+1。例如,(3、4、5),(5、12、13),(7、24、25)、(9、40、41)

2. 大于2的任意偶数2n(n>1) ,都可构成一组勾股数,

三边分别是:a=2*n、b=n^2-1、c=n^2+1。(6、8、10),(8、15、17),(10、24、26)。

3. a=m^2-n^ 2, b=2*m*n,c=m^2+n^2 (其中正整数m >n >0)。

4. 如果要得到一组互质的勾股数,则可以用以下规律计算:a=4n,b=4n^2-1,c=4n^2+1(n为正整数) 

?
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#define CLR(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
inline int rd(void) {
	int x=0;
	int f=1;
	char s=getchar();
	while(s<'0'||s>'9') {
		if(s=='-')f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9') {
		x=x*10+s-'0';
		s=getchar();
	}
	x*=f;
	return x;
}

int main() {
	int T;
	ll n,a;
	cin>>T;
	while(T--) {
		scanf("%lld%lld",&n,&a);
		if(n>2||n==0) {
			printf("-1 -1\n");
		} else if(n==1) {
			printf("%lld %lld\n",1,a+1);
		} else {
			if(a<=2) {
				printf("-1 -1\n");
			} else if(a%2==1) {
				ll nn=(a-1)/2;
				printf("%lld %lld\n",2*nn*(nn+1),2*nn*(nn+1)+1);
			} else {
				ll nn=a/2;
				printf("%lld %lld\n",nn*nn-1,nn*nn+1);
			}
		}
	}
}

?

Find Integer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 681    Accepted Submission(s): 78
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

 

 

Source

2018中国大学生程序设计竞赛 - 网络选拔赛

posted @ 2018-08-25 22:11  光芒万丈小太阳  阅读(157)  评论(0编辑  收藏  举报