# Maximize LCM | CodeChef

I would very much understand if my code gives Wrong Answer as verdict why am I getting RTE tho? Can someone help?

Because of overflow, LCM of a lot of numbers wont fit into any data type.

If it is a datatype problem, wouldn’t that give WA?

Well since in your code lcm will overflow quickly, values in your variables will contain some trash values(maybe negative, maybe 0) and because of that you may divide by 0 or pass negative variable to gcd function. So in short, overflow may cause a lot of weird behaviors and give different weird errors and probably that’s why it gives RTE error

1 Like

Why is this python code producing wrong answer as verdict. What is wrong with the logic please tell.

def gcd(a, b):
if(b == 0):
return a
return gcd(b, a%b)

def findlcm(l, n):
ansx = l
for i in range(1,n):
ansx = lcm(ansx, l[i])
return ansx
def lcm(a, b):
return (a*b)/gcd(a,b)

def solve():
n, m = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
init_lcm = findlcm(l, n)
ans = 1
track = init_lcm
for i in range(1, m + 1):
mv = lcm(init_lcm, i)
if(mv > track):
track = mv
ans = i
print(ans)

t =int(input())
while(t > 0):
t -= 1
solve()

Thanks @janpe

https://www.codechef.com/viewsolution/30867121
What is wrong in my solution? It does not pass some test cases.