Find Integer
people in USSS love math very much, and there is a famous math problem .
give you two integers , ,you are required to find integers , such that .
Input
one line contains one integer ;
next lines contains two integers , ; ( )
Output
print two integers
,
if
,
exits; (
);
else print two integers -1 -1 instead.
Sample Input
1
2 3
Sample Output
4 5
answer
, gives
, obtained
When
by Fermat's last theorem shows that no solution.
when
, the take
to
when
, the
if
is an odd number,
If the
is an even number,
C ++ code
#include <iostream>
using namespace std;
void solve(int n,int a){
if(n > 2 || n == 0){
printf("%d %d\n",-1,-1);
}else if(n == 1){
printf("%d %d\n",1,a + 1);
} else if(n == 2){
if(a % 2 == 1)
printf("%d %d\n",(a * a - 1)/2,(a * a + 1)/2);
else {
if (a == 2)
printf("%d %d\n",-1,-1);
else
printf("%d %d\n", (a * a / 4) - 1, (a * a / 4) + 1);
}
}
}
int main(){
int t;
cin >>t;
for(int i = 0;i < t;i++){
int n,a;
scanf("%d%d",&n,&a);
solve(n,a);
}
return 0;
}