题目链接
题意
现有\[x+y=a\\lcm(x,y)=b\]找出满足条件的正整数\(x,y\).
\(a\leq 2e5,b\leq 1e9,数据组数12W\).
思路
结论
\(gcd(x,y)=gcd((x+y),lcm(x,y))\)
证明
先证\(gcd(x,y)|gcd((x+y),lcm(x,y))\)
不妨设\(gcd(x,y)=k\),则有\(k\mid x,k\mid y\),则有\(k\mid (x+y)\) …①
又\(k\mid x,x\mid lcm(x,y)\),所以\(k\mid lcm(x,y)\) …②
综合①②有\(k\mid gcd((x+y),lcm(x,y))\).
再证\(gcd((x+y),lcm(x,y))|gcd(x,y)\)
设\(gcd((x+y),lcm(x,y))=k_0\),则有\(k_0|(x+y)\). 若\(k_0\nmid x\),则有\(k_0\nmid y\),否则\(k_0\nmid (x+y)\).
而若\(k_0\nmid x,k_0\nmid y\),则\(\exists d1,d1\mid k_0,d1\nmid x;\exists d2,d2\mid k_0,d2\nmid y\).而\(\forall d\mid lcm(x,y),有d\mid x或d\mid y\),...好像不太对......不会证了
// 待补
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a, b;
LL gcd(LL a, LL b) { return b ? gcd(b, a%b) : a; }
void work() {
LL k = gcd(a, b);
LL delta = a*a - 4*k*b;
if (delta < 0) { printf("No Solution\n"); return; }
LL ssqrt = sqrt(delta);
if (ssqrt*ssqrt != delta) { printf("No Solution\n"); return; }
LL den = a+ssqrt;
if (den&1) { printf("No Solution\n"); return; }
LL x = den/2;
LL y = a-x;
if (x > y) swap(x, y);
printf("%lld %lld\n", x, y);
}
int main() {
while (scanf("%lld%lld", &a, &b) != EOF) work();
return 0;
}