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.
Project Euler #5: Smallest multiple
Project Euler #5: Smallest multiple
Contest ends in
Sort by
recency
|
259 Discussions
|
Please Login in order to post a comment
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)
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)
Python
Gets prime factors of each number from 1 to N and "adds them together"
C#