HDUOJ 6441 Find Integer
题目链接
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=cna^n+b^n=c^nan+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
思维题~
首先根据费马大定理,当 n>2n>2n>2 时,一定无正整数解~
当 n=0n=0n=0 时,显然无解~
当 n=1n=1n=1 时,输出 111 和 a+1a+1a+1 即可
当 n=2n=2n=2 时,注意题目限定必须是正整数,我们考虑分奇偶,对 aaa 为奇数,a2a^2a2 可以拆分成 a2?1a^2*1a2?1;对 aaa 为偶数,a2a^2a2 可以拆分成 a22?2\frac{a^2}{2}*22a2??2,分别解一个二元一次方程即可~
注意输出的顺序,AC代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T,n,a;
int main(){
scanf("%d",&T);while(T--){
scanf("%d%d",&n,&a);if(n>2||n==0) printf("-1 -1\n");else if(n==2){
if(a%2) printf("%d %d\n",(a*a-1)/2,(a*a+1)/2);else printf("%d %d\n",a*a/4-1,a*a/4+1);}else if(n==1){
printf("1 %d\n",a+1);}}return 0;
}