Least Common Multiple in Python
The Least Common Multiple (LCM) is also referred to as the Lowest Common Multiple (LCM) and Least Common Divisor (LCD). For two integers a and b, denoted LCM(a,b), the LCM is the smallest positive integer that is evenly divisible by both a and b. For example, LCM(2,3) = 6 and LCM(6,10) = 30.
The LCM of two or more numbers is the smallest number that is evenly divisible by all numbers in the set.
How to Find the LCM in Python
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if ((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
Example
number_1
number_2
f"The Least Common Multiple of {number_1} and {number_2} is is {lcm(int(number_1), int(number_2))}"