Find Integer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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.
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)
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.
else print two integers -1 -1 instead.
Sample Input
1
2 3
Sample Output
4 5
分析:根据费马大定理:n>2时无解
只要考虑n=0,1,2
n=0时,无解
n=1时,随意构造两个数满足a+b=c
n=2时,随意构造一组勾股数满足a*a+b*b=c*c
AC代码:
#include <map> #include <set> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define ls (r<<1) #define rs (r<<1|1) #define debug(a) cout << #a << " " << a << endl using namespace std; typedef long long ll; const ll maxn = 1e6+10; const ll mod = 998244353; const double pi = acos(-1.0); const double eps = 1e-8; int main() { ios::sync_with_stdio(0); ll T; scanf("%lld",&T); while( T -- ) { ll n, a, b, c; scanf("%lld%lld",&n,&a); if( n >= 3 || n == 0 ) { printf("-1 -1 "); } else if( n == 1 ) { printf("1 %lld ",a+1); } else { ll h = 1; while( a%2 == 0 ) { a = a/2; h = h*2; } ll s, t; s = a; t = 1; b = (s*s-t*t)/2; c = (s*s+t*t)/2; b = b*h; c = c*h; printf("%lld %lld ",b,c); } } return 0; }