#!/usr/bin/env python
import timeit
from functools import partial, reduce

def gcd(a, b):
    """Greatest common divisor (factor)."""
    while b: # Euclid's algorithm
        a, b = b, a % b
    return a

def lcm(*args):
    """Least common multiple."""
    # lcm(a, b, c) == lcm(lcm(a, b), c)
    return reduce(lambda a, b: a * b // gcd(a, b), args)

def f(n):
    """Smallest positive number evenly divisible by all numbers from 1
       to n including.
    """
    return lcm(*range(1, n + 1))

print(f(10)) # -> 2520
print(f(50)) # -> 3099044504245996706400

def measure():
    for n in [10, 50, 100]:
        print("%3d: %5.2f microseconds" % (n, 100*timeit.timeit(partial(f, n),
                                                           number=1000*10)))
measure()
