If you’re checking each and every possibly number starting from 2, then the loop will have to go on for hundreds of thousands of times (if the lcm is 360 360, for example). After a certain amount of time, the computer will automatically stop looping. Hence, if the lcm isn’t too big, this computer can handle it, but if lcm is huge number, the computer will give up.
Yeah, I had the same problem. Computer just won’t do 360 360 loops. It cuts out after a certain amount of time. You’ll have to reduce the number of loops by checking in multiples of the product of the two biggest numbers in your array (as suggested in the hints).
I’m not sure why this works mathematically. Intuitively, it makes sense, but it assumes that the LCM will always be divisible by the product of the two biggest numbers, plus a third a number. Again, that makes sense, but I don’t like accepting things based on “it makes intuitive sense”. I’d like to see some math proof.
Yea, I wish I understood the math behind that. Learning programming at a later age and not using math for so long has really exposed how weak my math skills have become.
Anyways, thank you for the help! I got the problem solved by checking in multiples of the product of the two array elements given as arguments and it passed. I’m sure that checking from the two highest numbers in the range would have been much more efficient but I didn’t know that would work mathematically.