people in USSS love math very much, and there is a famous math problem .
give you two integers nn,aa,you are required to find 22 integers bb,cc such that anan+bn=cnbn=cn.
Input
one line contains one integer TT;(1≤T≤1000000)(1≤T≤1000000)
next TT lines contains two integers nn,aa;(0≤n≤1000(0≤n≤1000,000000,000,3≤a≤40000)000,3≤a≤40000)
Output
print two integers bb,cc if bb,cc exits;(1≤b,c≤1000(1≤b,c≤1000,000000,000)000);
else print two integers -1 -1 instead.
Sample Input
1 2 3
Sample Output
4 5
勾股数组定理:
每个本原勾股数组(a, b, c)(其中a为奇数,b为偶数)有公式:,
其中s>t>=1是任意没有公因数的整数.
但是这样写过不了会WR,代码
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
#include<bitset>
using namespace std;
#define ll long long
const int mod=258280327;
const int maxn=1e6+10;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
ll solve(ll n)
{
for(ll i=1; i<=sqrt(n); i++)
{
if(n%i==0&&n!=i*i)
{
ll p=n/i,q=i;
// cout<<p<<' '<<q;
if((p*p+q*q)%2==0&&(p*p-q*q)%2==0)
return (p*p+q*q)/2;
}
}
return 0;
}
int main()
{
ll t,n,a;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&n,&a);
if(n==1)
printf("1 %lld\n",a+1);
else if(n==2)
{
ll x=solve(a);
//cout<<x<<endl;
if(x==0)
printf("-1 -1\n");
else
{
printf("%lld %lld\n",(ll)(sqrt(x*x-a*a)),x);
}
}
else
printf("-1 -1\n");
}
return 0;
}
用勾股数规律就行(应该是卡这个吧),代码:
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
#include<bitset>
using namespace std;
#define ll long long
const int mod=258280327;
const int maxn=1e6+10;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
ll t,n,a;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&n,&a);
if(n==1)
printf("1 %lld\n",a+1);
else if(n==2)
{
ll s,b,c;
if(a%2 == 1)
{
b = a * a /2;
c = b + 1;
}
else
{
s = a * a / 2;
b = s / 2 - 1;
c = s / 2 + 1;
}
printf("%lld %lld\n", b, c);
}
else
printf("-1 -1\n");
}
return 0;
}
奇数的话:if(a%2 == 1) b = a * a /2, c = b + 1;
偶数的话: if(a%2 == 0)s = a * a / 2,b = s / 2 - 1, c = s / 2 + 1;