天天看點

用Python解答 ProjectEuler問題(5)

E005

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 number that is evenly divisible by all of the numbers from 1 to 20?

能被1到20整除的數最小是多少?

from prime import Prime

def problem5():
    pri = Prime(20)
    #求pri.primes中所有元素的乘積
    def mul(x, y): return x*y
    max_power = reduce(mul, pri.primes, 1)
    return max_power


if __name__=='__main__':
    print str(problem5())
      

“能被1到20整除”也就是“能被1到20中的素數整除”,又一個與素數有關的問題