python newbie——PE No.5

2520是最小的能被1-10中每个数字整除的正整数。

最小的能被1-20中每个数整除的正整数是多少?

def gcd(a, b):
    product = a * b
    while b != 0:
        t = b
        b = a % b
        a = t
    return product / a

temp = gcd(1, 2)

for i in range(3, 21):
    temp = gcd(temp, i)
print temp

<<<

232792560

欧几里德算法。

posted on 2013-04-04 21:28  XLiao  阅读(147)  评论(0编辑  收藏  举报