galois.lcm

class galois.lcm(*integers)

Computes the least common multiple of the integer arguments.

Note

This function is included for Python versions before 3.9. For Python 3.9 and later, this function calls math.lcm() from the standard library.

Returns

The least common multiple of the integer arguments. If any argument is 0, the LCM is 0. If no arguments are provided, 1 is returned.

Return type

int

Examples

In [559]: galois.lcm()
Out[559]: 1

In [560]: galois.lcm(2, 4, 14)
Out[560]: 28

In [561]: galois.lcm(3, 0, 9)
Out[561]: 0

This function also works on arbitrarily-large integers.

In [562]: prime1, prime2 = galois.mersenne_primes(100)[-2:]

In [563]: prime1, prime2
Out[563]: (2305843009213693951, 618970019642690137449562111)

In [564]: lcm = galois.lcm(prime1, prime2); lcm
Out[564]: 1427247692705959880439315947500961989719490561

In [565]: lcm == prime1 * prime2
Out[565]: True