You are viewing a single comment's thread. Return to all comments →
import math from functools import reduce
def lcm(a, b): return abs(a*b) // math.gcd(a, b)
def lcm_of_range(n): return reduce(lcm, range(1, n+1))
t = int(input().strip()) for _ in range(t): n = int(input().strip()) result = lcm_of_range(n) print(result)
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 math from functools import reduce
def lcm(a, b): return abs(a*b) // math.gcd(a, b)
def lcm_of_range(n): return reduce(lcm, range(1, n+1))
Input handling
t = int(input().strip()) for _ in range(t): n = int(input().strip()) result = lcm_of_range(n) print(result)