A Simple Math Problem(hdu 5974 数论题
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5974
已知:X+Y=a,lcm(X,Y)=b,给出a,b取值求解X,Y
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> using namespace std; #define ll long long ll gcd(ll n,ll m) { return m==0?n:gcd(m,n%m); } int main() { int i,j,t,n,m,a,b; while(~scanf("%d%d",&a,&b)) { ll g=gcd(a,b); ll A=a/g; ll B=b/g; ll deita=A*A-4*B; if(deita<0)cout<<"No Solution\n"; else { ll z1=(-A+sqrt(deita)); ll z2=(-A-sqrt(deita)); ll de=sqrt(deita); if(z1%-2==1||z2%-2==1||de*de!=deita)cout<<"No Solution\n";//非整数情况 else cout<<min(z1/(-2),z2/(-2))*g<<" "<<max(z1/(-2),z2/(-2))*g<<endl; }//由韦达定理得两根都是正数;所以两个解一个是p一个是q,再*g就是x,y了 } return 0; }