Cake
Cake
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3519 Accepted Submission(s): 1829
Problem Description
一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食.
Input
每行有两个数p和q.
Output
输出最少要将蛋糕切成多少块.
Sample Input
2 3
Sample Output
4
Hint
将蛋糕切成大小分别为1/3,1/3,1/6,1/6的四块即满足要求.
当2个人来时,每人可以吃1/3+1/6=1/2 , 1/2块。
当3个人来时,每人可以吃1/6+1/6=1/3 , 1/3, 1/3块。#include<cstdio>
int yue(int a,int b)
{
if(a%b==0)
return b;
else
return yue(b,a%b);
}
int main ()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
printf("%d\n",n+m-yue(n,m));
}
return 0;
}
编程五分钟,调试两小时...