Help! What is wrong with my Euclidean GCD function?

I am trying to get through the Array Filling problem of August Long Challenge, but something seems to be wrong with my code. On submission, the result which is coming is a Runtime Error, and I think the problem might actually be in my Euclidean GCD method. Can anyone go through it in my code and let me know what is it?

My submission :

https://www.codechef.com/viewsolution/51025396

Probably some sort of an overflow in the LCM function. I am not good with JAVA, so not sure. But, you GCD function is overkill. Here’s a simpler version (in C++)

int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }

Oh, okay. That will work too, thanks! :slight_smile: