【2016ACM/ICPC亚洲区大连站D】HDU - 5974 A Simple Math Problem 数论推公式

题意

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值