LCM (Least Common Multiple) of two numbers is the smallest number which can be divided by both numbers.
For example LCM of 15 and 20 is 60 and LCM of 5 and 7 is 35.
A simple solution is to find all prime factors of both numbers, then find union of all factors present in both numbers. Finally return product of elements in union.
An efficient solution is based on below formula for LCM of two numbers ‘a’ and ‘b’.
a x b = LCM(a, b) * GCD (a, b) LCM(a, b) = (a x b) / GCD(a, b)
We have discussed function to find GCD of two numbers. Using GCD, we can find LCM.
Below is the implementation of above idea :
LCM of 15 and 20 is 60
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Program to find GCD or HCF of two numbers
- Program to find LCM of 2 numbers without using GCD
- Program to find sum of first n natural numbers
- Program to find sum of prime numbers between 1 to n
- Program to find first N Iccanobif Numbers
- Program to find LCM of two Fibonnaci Numbers
- C program to Find the Largest Number Among Three Numbers
- Program to find the percentage of difference between two numbers
- Program to find GCD of floating point numbers
- Program to find the common ratio of three numbers
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Program to find the maximum difference between the index of any two different numbers
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Program to find count of numbers having odd number of divisors in given range
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.