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;
}

浙公网安备 33010602011771号