hdu---1722 Cake

来源:互联网 发布:惊天动地影评知乎 编辑:程序博客网 时间:2024/05/22 00:09

Cake

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2313    Accepted Submission(s): 1203


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块。



AC:

#include <iostream>#include <algorithm>#include <string.h>#include <math.h>#include <stdio.h>#include <queue>using namespace std;#define N 10010#define Mod 10#define LL long longint gcd(int a,int b){return a%b==0 ? b : gcd(b,a%b);}/* */int main(){//freopen("in.in","r",stdin);//freopen("out.out","w",stdout);int a,b;while(scanf("%d %d",&a,&b)!=EOF){printf("%d\n",a+b-gcd(a,b));}return 0;}


0 0