Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:感觉没错呀,为什么会wa?

Posted by 15063887278 at 2020-07-01 19:02:40 on Problem 2429
In Reply To:感觉没错呀,为什么会wa? Posted by:15063887278 at 2020-07-01 19:01:55
> 设 $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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator