The lcm() function of python math module

The lcm() function returns the least common multiple for a given set of of integers.

Math Updated 23 Jun 2022 1 min read

Overview

  • For a set of integers, the function lcm() returns the least common multiple of them.
  • The least common multiple(lcm) is the integer that is divisible by the each of the input parameter.
  • If one of the parameters is zero, the lcm() returns zero.

Example

python
# Example Python program that finds

            # the least common multiple of a set

            # of integers

import math

lcm = math.lcm(3, 6, 9)

            print(lcm)

lcm = math.lcm(7, 13)

            print(lcm)

lcm = math.lcm(0, 10)

            print(lcm)

Output

Output
18

91

0