Cake

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<stdio.h>
int gcd(int x,int y)
{
    int t=1;
    while(t)
    {
        t=x%y;
        x=y;
        y=t;
    }
    return x;
}
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int s;
        s=m+n-gcd(m,n);   //核心!!!!
        printf("%d\n",s);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/liufei-/p/9338845.html
今日推荐