Python Tutorial Python Advanced Python References Python Libraries

Python math - lcm() Function



The Python math.lcm() function returns the least common multiple of the specified integer arguments. If all arguments are nonzero, then the returned value is the smallest positive integer which is a multiple of all arguments. If any of the arguments is zero, then the returned value is 0. If no argument is provided, it returns 1.

For example - LCM of 20 and 25 is 100, and LCM of 50 and 100 is 100.

Note: This function is added in version 3.9.

Syntax

#New in version 3.9
math.lcm(*args)

Parameters

*args Required. Specify the variable number of integer values separated by comma ,.

Return Value

Returns the LCM of the specified arguments.

Example:

In the example below, lcm() function returns the LCM of the specified arguments.

import math

print(math.lcm(10, 20, 25))
print(math.lcm(4, 5))

The output of the above code will be:

100
20

❮ Python Math Module