Skip to content


Least common multiple

Returns the least common multiple of a list of numbers.

from functools import reduce
from math import gcd

def lcm(numbers):
  return reduce((lambda x, y: int(x * y / gcd(x, y))), numbers)

lcm([12, 7]) # 84
lcm([1, 3, 4, 5]) # 60

More like this

Start typing a keyphrase to see matching snippets.