杭电 hdu 2504

又见GCD:

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


你可能感兴趣的:(ACM,HDU,杭电,2504)