よしたく blog

ほぼ週刊で記事を書いています

【Project Euler】Problem 5 Smallest multipleをPythonで解く

この問題をPythonで解いた。

#5 Smallest multiple - Project Euler

日本語の問題文はこちら

2520 は 1 から 10 の数字の全ての整数で割り切れる数字であり, そのような数字の中では最小の値である.

では, 1 から 20 までの整数全てで割り切れる数字の中で最小の正の数はいくらになるか.

Problem 5 - PukiWiki

from math import gcd
from functools import reduce

def lcm(a,b):
    return a*b//gcd(a,b)

print(reduce(lcm, range(1,21)))