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