| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
感觉没错呀,为什么会wa?设 x=gcd(a,b),y=lcm(a,b)
则 x*y=gcd(a,b)*lcm(a,b)=gcd(a,b)*a*b/gcd(a,b)=a*b
然后枚举x,找到一个最小的x+y就好了,但是wa...
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a,b,mul,minn=1e9,x,y;
int main()
{
scanf("%lld%lld",&a,&b);
mul=a*b;
for(register ll i=1;i*i<=mul;i++)
{
if(mul%i!=0) continue;
int now=mul/i;
if(minn>now+i)
{
minn=now+i;
x=i,y=now;
}
}
if(x>y) swap(x,y);
printf("%lld ll%d\n",x,y);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator