Problem 5 Smallest multiple

来源:互联网 发布:申万宏源交易软件下载 编辑:程序博客网 时间:2024/06/05 04:52

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?


prime = [ 2,3,5,7,11,13,17,19]result = 1for i in prime:result *= ifor i in range(2,21):if result % i==0:continuetmp = ifor j in prime:if tmp % j == 0:tmp = tmp / jresult *= tmpprint result


def gcd(a,b):        if b == 0:return a        else:return gcd(b,a%b)def lcm(a,b):        return ( a/gcd(a,b) )*br = 2for i in range(3,21):        r = lcm(r,i)print r

原创粉丝点击