太天真了,以为
104
直接跑暴力了,结果T到哭泣,12W的数据量,只能用公式求。
这个题要推出来
gcd(x,y)=gcd(a,b)
,然后转换成一元二次方程的韦达定理,接下来就是验证方程是否有整数解。
code:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<string>
#include <set>
#include<time.h>
//a&3==a%4
using namespace std ;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const double eps = 1e-8;
const int maxn = 110010;//须填写
const int inf = 0x3f3f3f3f;
ll gcd(ll a,ll b)
{
return a==0?b:gcd(b%a,a);
}
int main()
{
ll a,b;
while(scanf("%lld%lld",&a,&b)!=EOF)
{
ll g=gcd(a,b);
a/=g;
b/=g;
if(a*a-4LL*b<0LL)
{
printf("No Solution\n");
}
else
{
ll x=(a+sqrt(a*a-4*b))/2;
ll y=a-x;
ll tmp;
if(x*y==b)
{
if(x>y)
{
tmp=x;
x=y;
y=tmp;
}
printf("%lld %lld\n",x*g,y*g);
}
else
{
printf("No Solution\n");
}
}
}
return 0;
}
//寇瑟茹酒