To calculate the LCM of two given numbers
The abbreviation LCM stands for "Least Common Multiple". The least common multiple of two numbers is the lowest possible number that can be divisible by both numbers. It can be calculated for two or more integers as well as two or more fractions.
There are multiple methods to find the LCM of two numbers. One of the quickest ways to find the LCM of two numbers is to use the prime factorization of each number and then the product of the highest powers of the common prime factors will be the LCM of those numbers.
The least common multiple is also known as LCM (or) the lowest common multiple in math. The least common multiple of two or more numbers is the smallest number among all common multiples of the given numbers. Let's take two numbers: say, 2 and 5. Each will have its own set of multiples.
By using the listing out the common multiples method we can find out the common multiples of two or more numbers. Out of these common multiples, the least common multiple is considered and the LCM of two given numbers can thus be calculated. To calculate the LCM of the two numbers A and B by the listing method, follow the steps given below:
Enter the first number(A):
Enter the second number(B):
Here's the result
# Python Program to find the L.C.M. of two input number
def compute_lcm(x, y):
# choose the greater number
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
num1 = 54
num2 = 24
print("The L.C.M. is", compute_lcm(num1, num2))
Hence we can findout the LCM of two given numbers.