Please someone tell me whats wrong in the following code. It works for the test case given in the question but still on submitting it gives wrong answer.
#include
using namespace std;
int main()
{
int T,A,B,n,d,r,gcd,lcm;
cin>>T;
for(int i=0; i<T; i++)
{
cin>>A>>B;
if (A>B)
{
n=A;
d=B;
}
else
{
n=B;
d=A;
}
r=n%d;
while (r!=0)
{
n=d;
d=r;
r=n%d;
}
gcd=d;
lcm=(A*B)/gcd;
cout<<gcd<<" "<<lcm<<endl;
}
return 0;
}