最大公約数・最小公倍数を求める
math.gcd(x, y)を用いる (Python 3.5以降)
code:py
import math
from functools import reduce
def gcm_list(numbers):
return reduce(gcm, numbers)
gcdを用いて自前で用意する
code:py
import math
from functools import reduce
def lcm(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm, numbers)