Title:
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.
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.
Title:
Here are two numbers for you. N is the index, a is the base. Find b and c to satisfy a^n+b^n=c^n.
In fact, it's Fermat's theorem. When n > 2, there is no integer, and = 2 is the Pythagorean number. Here we investigate the construction of Pythagorean number,
In the original formula:
a is odd 2n+1, b = 2n^2+2n, c = b+1;
When a is even 2n greater than 4, b = n^2-1, c = n^2+1;
In this way, Pythagorean number can be constructed, but this problem is T....
So, later, by constructing the original number of shares, preprocessing, it passed.
Preprocessing Code:
void ppt(){
ll s,t;
for(s = 3; s <= 40000; s += 2){
for(t = 1; t < s; t += 2){
if(__gcd(s,t) == 1) {
ll a = s*t;
if(a > 40000)
break;
ll b = (s*s-t*t)/2;
ll c = (s*s+t*t)/2;
A[a][0] = b;
A[a][1] = c;
if(b > 40000)
break;
A[b][0] = a;
A[b][1] = c;
}
}
}
}
Code:
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
int t;
ll n,m;
while(cin >> t){
cin >> n >> m;
if(n > 2)
cout << -1 << " " << -1 << endl;
else{
if(n == 0){
cout << -1 << " " << -1 << endl;
}
if(n == 1)
{
cout << 1 <<" " << m+1 << endl;
}
if(n == 2){
if(m <= 2){
cout << -1 << " " << -1 << endl;
}
else{
int x = 0;
if(m % 2){
x = (m-1)/2;
cout << 2*x*x+2*x << " " << 2*x*x+2*x+1 << endl;
}
else{
x = m/2;
cout << x*x-1 << " " << x*x+1 << endl;
}
}
}
}
}
}