Error in calculating GCD and LCM

I have written the below code to calculate the GCD and LCM.

It works fine for the given set of inputs in the question as well as for some other inputs which i tried.

If when running on codechef it says Wrong Answer.

Not sure what is causing this error.

This is the link to the solution

Advise on what is wrong in the code.


1000000 1000000

since a and b are of order 10^6 so a*b will not fit in an integer hence lcm will overflow. Use long for a and b or typecast them accordingly while calculating LCM