+2 votes
in Programming Languages by (73.2k points)
How to compute the lowest common multiple of numbers in Python?

E.g.

lcm(10,12) = 60

1 Answer

+1 vote
by (346k points)
selected by
 
Best answer

Numpy has a function lcm(). You can use it to compute the lowest common multiple of numbers.

If you have only 2 numbers:

>>> import numpy as np
>>> np.lcm(10,12)
60

If you have more than 2 numbers:

>>> np.lcm.reduce([10,12,15,18,17])
3060
>>> np.lcm.reduce([2,4,8,12])
24


...