题意
x+y=a lcm(x,y)=b 求x,y
12WCases + b 10^9 + a 10^4
http://acm.hdu.edu.cn/showproblem.php?pid=5974
分析
数据范围知肯定不是枚举……肯定是公式题
代码
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 using namespace std;
7 typedef
long long ll;
8 ll gcd(ll a,ll b)
9 {
10 return b==
0?a:gcd(b,a%
b);
11 }
12 int main()
13 {
14 ll a,b;
15 while(scanf(
"%lld%lld",&a,&b)!=
EOF){
16 ll c=
gcd(a,b);
17 ll d=a*a-
4*b*
c;
18 if(d<
0){
19 printf(
"No Solution\n");
20 continue;
21 }
22 ll i=(a-sqrt(d))/
2/
c;
23 ll j=a/c-
i;
24 ll x=c*
i;
25 ll y=c*
j;
26 if(x*y==b*
c)
27 printf(
"%lld %lld\n",x,y);
28 else
29 printf(
"No Solution\n");
30 }
31 }
转载于:https://www.cnblogs.com/helloWR/p/10909926.html