题目链接
大意:给你两个数 X , Y X,Y X,Y,让你找两个数 a , b a,b a,b,满足 a + b = X , l c m ( a , b ) = Y a+b=X,lcm(a,b)=Y a+b=X,lcm(a,b)=Y.
思路:枚举 g c d ( a , b ) gcd(a,b) gcd(a,b),假设 g c d ( a , b ) = k a = x a k , b = x b k , gcd(a,b)=k,那么a=x_a*k,b=x_b*k, gcd(a,b)=ka=xak,b=xbk,化简上面给的两个式子即可得到
x a + x b = X k , x a x b = Y k x_a+x_b=\frac{X}{k},x_a*x_b=\frac{Y}{k} xa+xb=kX,xaxb=kY,显然这是一个方程组,将 x b = X k x a x_b=\frac{X}{k}-x_a xb=kXxa代入第二个式子即可得到一个一元二次方程,解这个方程即可。

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int a,b;
int main(){
	ios::sync_with_stdio(false);
	while(cin>>a>>b){
		int q=sqrt(a);
		int sta=0,anL,anR;
		for(int i=1;i<=q;i++){
			if(a%i)continue;
			int A=a/i;
			int B=b/i;
			if(A*A<4*B)continue;
			int T=floor(sqrt(A*A-4*B));
			if(T*T!=A*A-4*B)continue;
			else {
				if((A-T)%2||(A+T)%2)continue;
				int L=(A-T)/2*i;
				int R=(A+T)/2*i;
				if(lcm(L,R)!=b)continue;
				anL=(A-T)/2*i;
				anR=(A+T)/2*i;
				sta=1;
				break;
			}
		}
		for(int i=1;i<=q&&!sta;i++){
			if(a%i)continue;
			int A=a/(a/i);
			int B=b/(a/i);
			if(A*A<4*B)continue;
			int T=floor(sqrt(A*A-4*B));
			if(T*T!=A*A-4*B){continue;}
			else {
				if((A-T)%2||(A+T)%2){continue;}
				int L=(A-T)/2*(a/i); 
				int R=(A+T)/2*(a/i);
				if(lcm(L,R)!=b){continue;}
				anL=(A-T)/2*(a/i);
				anR=(A+T)/2*(a/i);
				sta=1;
				break;
			}
		}
		if(!sta)cout<<"No Solution\n";
		else cout<<anL<<' '<<anR<<endl;
	}
	return 0;
}