|
CakeTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3337 Accepted Submission(s): 1734
Problem Description
一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食.
Input
每行有两个数p和q.
Output
输出最少要将蛋糕切成多少块.
Sample Input
Sample Output
Author
LL
Source
|
一个圆切成p 块,切成q 块,重复刀印最多有gcd(q,p)个,
代码:
#include<cstdio>
#include<algorithm>
int gcd(int dd,int xx)
{
int c;
if (dd<xx)
{
c=dd;dd=xx;xx=c;
}
if (dd%xx)
return gcd(xx,dd%xx);
return xx;
}
int main()
{
int p,q;
while (~scanf("%d%d",&q,&p))
printf("%d\n",q+p-gcd(q,p));
return 0;
}