V-Lab @ ANDC

To calculate the LCM of two given numbers

Aim

To calculate the LCM of two given numbers

Theory

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.

  • Multiples of 2 are 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, …
  • Multiples of 5 are 5, 10, 15, 20, …

Procedure

    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:

    1. List the first few multiples of number A and B.
    2. Mark the common multiples from the multiples of both numbers.
    3. Select the smallest common multiple. That lowest common multiple is the LCM of the two numbers.

Practice

Enter the first number(A):

Enter the second number(B):

Here's the result




Python Code

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

Result

Hence we can findout the LCM of two given numbers.