# coding=utf-8 ''' 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? ''' from time import time gcd = lambda x, y: (y == 0) and x or gcd(y, x % y) def p1(maxx = 20): maxx += 1 num = [] for i in range(maxx): num.append(i) for i in range(2, maxx): if num[i] > 1: for j in range(i + 1, maxx): if num[j] % num[i] == 0: num[j] /= num[i] total = 1 for i in num[1 : maxx]: total *= num[i] #print num print total def p2(maxx = 20): n = 2 for i in xrange(3, maxx + 1): if n % i != 0: n = n * i / gcd(n, i) return n #p1(20) print p2(50000)