WA: Couldn't find the reason of the solution of gcd problem

I have used the built-in gcd. Still got WA till I was using int to get GCD & LCM. My code provides correct answers up to the limit. After using long long it got accepted. I don’t understand why I got WA if it was giving correct answers up to the limits. Can somebody explain? @anon46046035, @anumber have a look.

GCD Problem: gcd & lcm
WA solution: using int
AC solution: using long long

Take the two largest prime no. <=1000000 , so their GCD will be 1 , and thus leading their LCM to be more than 10^11 , which is way above limit of int

1 Like

Thanks @dhruv788 for the reply. Yep, the gcd and lcm of 999983 and 1000000 are 1 and a 10^11 number.

sorry for no reply

Yeah! I think u got the answer. See the constraints given. When u multiply two prime no, the lcm will be their product. And as per the given constraints, int cannot hold a*b. So long long should be used here.