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?

first we create a function that factorizes an integer:


In [51]:
def factorize(n):
    i = 1
    while n != 1:
        i += 1
        while n % i ==0:
            n /= i
            yield i

test if it works:


In [52]:
from collections import Counter
c = Counter(factorize(124))
print(c)


Counter({2: 2, 31: 1})

now we factorize for each number, and keep the maximum number of factors:


In [56]:
all_count = Counter()
n = 20
for integer in range(2,n):
    cur = Counter(factorize(integer))
    for factor in cur.keys():
        all_count[factor] = max(all_count[factor], cur[factor])

print(all_count)


Counter({2: 4, 3: 2, 19: 1, 17: 1, 5: 1, 7: 1, 11: 1, 13: 1})

finally just multiply it:


In [53]:
p = 1
for i in all_count.keys():
    p *= pow(i, all_count[i])
print(p)


232792560