您的位置:首页 > 其它

HDU 2504 又见GCD

2010-09-27 12:30 260 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2504

代码

#include <iostream>
using namespace std;

int gcd(int a,int b)
{
while(a%b)
{
int r=a%b;
a=b;
b=r;
}
return b;
}

int main()
{
int n,a,b,c,i,j;
cin>>n;
for (i=0;i<n;i++)
{
cin>>a>>b;
c=2*b;
while(gcd(a,c)!=b)
{
c+=b;
}
cout<<c<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: