Correct code, but getting Wrog answer on submitting, FLOW016

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

Following line is faulty.

lcm=(A*B)/gcd;

A * B can be of order 10^{12} which is more than what int can store.

1 Like