hdu 1722 Cake

公式:p+q-GCD(q,p)

具体分析:

http://www.shuxueweb.com/shuxuebolan/qiuti/shuxuebolan_9112.html

#include<iostream>
using namespace std;
int hcf(int a,int b)
{
    int r=0;
    while(b!=0)
        {
        r=a%b;
        a=b;
        b=r;
        }
    return(a);
} 
int main()
{
	int q,p;
	while(cin>>q>>p)
	{
		cout<<q+p-hcf(q,p)<<endl;
	}
	return 0;
}
posted @ 2011-09-05 20:33  枕边梦  阅读(202)  评论(0编辑  收藏  举报