What's wrong in this approach MXMLCM. [WA]

I’m trying different approach and I know I’m wrong but where?
What I’m trying to do is finding the maximum prime number within range [m]. and if this prime number is not in the sequence than printing this as the answer. The idea behind this is that LCM is nothing but the multiplication of prime numbers.
So if I able to add one new prime number into it I’ll get the maximum LCM.
Please tell me where I’m wrong in this approach?

1 Like

I’m not sure, but here’s what i think.
suppose your LCM is 3^2 * 5^1. (as product of prime number powers) and your m is 8.
so now the biggest prime number is 7. LCM = 3^2 * 5^1 * 7^1.
But, the answer would be 8 as LCM is max, 2^3 * 3^2 * 5^1.


Yes. You’re right. Actually I forgot about the co-primes and checking for strictly prime numbers.

1 Like