HDOJ2504
#include <iostream>
using namespace std;
bool Judge(int a,int b)
{
int tt,r;
if(a < b){tt = a; a = b; b = tt;}
r = a % b;
while(r)
{
a = b;
b = r;
r = a % b;
}
if(b != 1)return false;
else return true;
}
int main()
{
int a,b,i;
int n;
while(cin>>n)
while(n-- && cin>>a>>b)
{
a /= b;
for(i = 2;; i ++)
{
if(a % i != 0 && Judge(a,i))
{//因b为a和c的最大公倍数,此时a和c应当是无公倍数
cout<<i * b<<endl;
break;
}
}
}
return 0;
}
using namespace std;
bool Judge(int a,int b)
{
int tt,r;
if(a < b){tt = a; a = b; b = tt;}
r = a % b;
while(r)
{
a = b;
b = r;
r = a % b;
}
if(b != 1)return false;
else return true;
}
int main()
{
int a,b,i;
int n;
while(cin>>n)
while(n-- && cin>>a>>b)
{
a /= b;
for(i = 2;; i ++)
{
if(a % i != 0 && Judge(a,i))
{//因b为a和c的最大公倍数,此时a和c应当是无公倍数
cout<<i * b<<endl;
break;
}
}
}
return 0;
}