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 2023 © pythontic.com