hello kity

期待您的批阅,由于写解题报告时 不一定考虑的很周到,所以如果您有什么不懂的地方,请您留言,然而一天之内我肯定会看见您信息,再对代码注释详细,让您更好的阅读

分类

最新评论

最新留言

链接

RSS

计数器
223934

功能

HDU 1722(分蛋糕 规律性题目)
spoiler
posted @ 2011年4月17日 01:19
in 未分类
, 1981 阅读
一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食.
题目分析:p+q-gcd(p+q)
代码:
#include<iostream> #include<cstdio> using namespace std; int gcd(int a,int b){ int c; if(a<b){ c=a; a=b; b=c; } while(b){ c=b; b=a%b; a=c; } return a; } int main(){ int x,y; while(~scanf("%d %d",&x,&y)){ printf("%d\n",x+y-gcd(x,y)); } return 0; }