又见GCD

#pragma warning (disable:4786)
#include <iostream>
using namespace std;
int gcd(int a,int b)
{
    int ta=a,tb=b;
    while(ta)
    ta^=tb^=ta^=tb%=ta;
    return tb;
}
int main()
{  
    int a,b,n;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        int c=b*2;
        while(gcd(a,c)!=b)
            c+=b;
        cout<<c<<endl;
    }
    return 0;
}

 

posted @ 2013-09-19 15:14  Destino74  阅读(66)  评论(0编辑  收藏  举报