The lcm() function of python math module

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:

# 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:

18

91

0

 


Copyright 2024 © pythontic.com