We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import sys
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
t = int(input().strip())
for a0 in range(t):
n = int(input().strip())
a=n
for i in range(n-1,1,-1):
a=lcm(a,i)
print(a)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #5: Smallest multiple
You are viewing a single comment's thread. Return to all comments →
import sys def lcm(x, y): if x > y: greater = x else: greater = y while(True): if((greater % x == 0) and (greater % y == 0)): lcm = greater break greater += 1 return lcm t = int(input().strip()) for a0 in range(t): n = int(input().strip()) a=n for i in range(n-1,1,-1): a=lcm(a,i) print(a)