Find the other number when LCM and HCF given - GeeksforGeeks

04 Mar, 2021
Given a number A and L.C.M and H.C.F. The task is to determine the other number B.Examples:  
Input: A = 10, Lcm = 10, Hcf = 50.
Output: B = 50

Input: A = 5, Lcm = 25, Hcf = 4.
Output: B = 20
 
Formula:-  
A * B = LCM * HCF B = (LCM * HCF)/AExample : 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 * yNote that x and y are not common factors, so LCM must include HCF, x and y. So we can conclude. LCM = HCF * x * ySo LCM * HCF = HCF * x * y * HCF which is equal to A * B
Below is the implementation of the above approach:  
C++
Java
Python3
C#
PHP
Javascript
// CPP program to find other number from given// HCF and LCM#include <bits/stdc++.h>using namespace std; // Function that will calculates// the zeroes at the endint otherNumber(int A, int Lcm, int Hcf){    return (Lcm * Hcf) / A;} // Driver codeint main(){    int A = 8, Lcm = 8, Hcf = 1;     // Calling function.    int result = otherNumber(A, Lcm, Hcf);     cout << "B = " << result;     return 0;}
// Java program to find other number from given// HCF and LCMclass GFG{ // Function that will calculates// the zeroes at the endstatic int otherNumber(int A, int Lcm, int Hcf){    return (Lcm * Hcf) / A;} // Driver codepublic static void main(String args[]){    int A = 8, Lcm = 8, Hcf = 1;     // Calling function.    int result = otherNumber(A, Lcm, Hcf);     System.out.println("B = "+ result); }}
# Python 3 program to find other# number from given HCF and LCM # Function that will calculates# the zeroes at the enddef otherNumber(a, Lcm, Hcf):    return (Lcm * Hcf) // A # Driver codeA = 8; Lcm = 8; Hcf = 1 # Calling functionresult = otherNumber(A, Lcm, Hcf)print("B =", result) # This code is contributed# by Shrikant13
// C# program to find other number// from given HCF and LCMusing System; class GFG{ // Function that will calculates// the zeroes at the endstatic int otherNumber(int A, int Lcm,                              int Hcf){    return (Lcm * Hcf) / A;} // Driver codestatic public void Main(String []args){    int A = 8, Lcm = 8, Hcf = 1;     // Calling function.    int result = otherNumber(A, Lcm, Hcf);     Console.WriteLine("B = " + result);}} // This code is contributed by Arnab Kundu
<?php// PHP program to find other number// from given HCF and LCM // Function that will calculates// the zeroes at the endfunction otherNumber($A, $Lcm, $Hcf){    return ($Lcm * $Hcf) / $A;} // Driver code$A = 8; $Lcm = 8; $Hcf = 1; // Calling function.$result = otherNumber($A, $Lcm, $Hcf); echo "B = " . $result; // This code is contributed// by Akanksha Rai
<script> // Javascript program to find other number from given// HCF and LCM // Function that will calculates// the zeroes at the endfunction otherNumber(A, Lcm, Hcf){    return (Lcm * Hcf) / A;} // Driver code     let A = 8, Lcm = 8, Hcf = 1;     // Calling function.    let result = otherNumber(A, Lcm, Hcf);     document.write("B = " + result);     // This code is contributed by Mayank Tyagi </script>
B = 1
 
Kirti_Mangal
andrew1234
Akanksha_Rai
shrikanth13
mayanktyagi1709
GCD-LCM
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Find all factors of a natural number | Set 1
Check if a number is Palindrome
Program to print prime numbers from 1 to N.
Program to add two binary strings
Fizz Buzz Implementation
Python Dictionary
Arrays in C/C++
Reverse a string in Java
Inheritance in C++
C++ Classes and Objects