此文参考网上的代码。。。刚开始有些没想通。。。组要还是需要自己动手切一下蛋糕最好
网上连接:http://blog.youkuaiyun.com/ilovexiaohao/article/details/8590583
杭电题地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=4
Cake |
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 1730 Accepted Submission(s): 815 |
Problem Description
一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食.
|
Input
每行有两个数p和q.
|
Output
输出最少要将蛋糕切成多少块. |
Sample Input
2 3 |
Sample Output
4 |
#include <iostream>
using namespace std;
int lcm(int a,int b)
{
while(b)
{
int k=a%b;
a=b;
b=k;
}
return a;
}
int main()
{
int m,n;
while(cin>>m>>n)
{
cout<<(m+n-lcm(m,n))<<endl;
}
return 0;
}