题目链接
题意:
给你一个p,q,问是否存在一组a,b均为整数,且a/b + b/a = p/q
分析:
看下面的图片吧
下面请看代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<climits>
#include<unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef unsigned long long ull;
const int mod = 1e9+7;
const int N = 100010;
int main(){
int T;
cin>>T;
while(T--){
LL p,q;
cin>>p>>q;
LL t = __gcd(p,q);p /= t;q /= t;
bool flag = false;
for(LL i=1;i*i<=p;i++){
int b = sqrt(p-i*i);
if((i*i + b*b) == p && i*b == q){
flag = true;
cout<<i<<" "<<b<<endl;
break;
}
}
if(!flag) cout<<"0 0"<<endl;
}
return 0;
}