Input: A = 10, Lcm = 10, Hcf = 50. Output: B = 50 Input: A = 5, Lcm = 25, Hcf = 4. Output: B = 20
A * B = LCM * HCF
B = (LCM * HCF)/A
Example : A = 15, B = 12
HCF = 3, LCM = 60
We can see that 3 * 60 = 15 * 12.
How does this formula work?
Since HCF divides both the numbers, let.
A = HCF * x
B = HCF * y
Note that x and y are not common factors, so LCM must include HCF, x and y.
So we can conclude.
LCM = HCF * x * y
So LCM * HCF = HCF * x * y * HCF which is equal to A * B
Below is the implementation of the above approach:
B = 1
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of LCM(1, n), LCM(2, n), LCM(3, n), ... , LCM(n, n)
- Count the number of subsequences of length k having equal LCM and HCF
- Number of pairs such that their HCF and LCM is equal
- LCM and HCF of fractions
- Minimum replacement of pairs by their LCM required to reduce given array to its LCM
- Program to find GCD or HCF of two numbers
- Program to find HCF iteratively
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Find HCF of two numbers without using recursion or Euclidean algorithm
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Given GCD G and LCM L, find number of possible pairs (a, b)
- HCF of array of fractions (or rational numbers)
- Find any pair with given GCD and LCM
- Find two numbers with the given LCM and minimum possible difference
- Find two numbers with given sum and maximum possible LCM
- Find the ratio of LCM to GCD of a given Array
- Find two distinct numbers such that their LCM lies in given range
- LCM of digits of a given number
- Minimum number to be added to minimize LCM of two given numbers
- Program to find LCM of two numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.