mu chance or much chance ?


Project Euler 5

  • 問題

Problem 5:Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

  • 解答例
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

def lcm(m, n):
    return (m * n) // gcd(m, n)

mul = 1
for x in range(1, 21):
    mul = lcm(mul, x)