HDUOJ 6441 Find Integer

HDUOJ 6441 Find Integer

Topic link

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 a n + b n = c n a^n+b^n=c^n 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

Thinking questions~
First, according to Fermat's Last Theorem, when n> 2 n>2n>When 2 , there must be no positive integer solution ~
whenn = 0 n=0n=At 0 , there is obviously no solution ~
whenn = 1 n=1n=When 1 , output1 11 suma + 1 a + 1a+1 is enough,
whenn = 2 n=2n=At 2 o'clock, note that the title limit must be a positive integer, we consider parity, foraaa is odd,a 2 a^2a2 can be split intoa 2 ∗ 1 a^2*1a21 ; toaaa is an even number,a 2 a^2a2 can be split intoa 2 2 ∗ 2 \frac{a^2}{2}*22a22. Solve a binary linear equation separately~
pay attention to the output order, the AC code is as follows:

#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;
}

Guess you like

Origin blog.csdn.net/qq_43765333/article/details/108670681