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 = 50Input: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++

`// 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 end ` `int` `otherNumber(` `int` `A, ` `int` `Lcm, ` `int` `Hcf) ` `{ ` ` ` `return` `(Lcm * Hcf) / A; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `A = 8, Lcm = 8, Hcf = 1; ` ` ` ` ` `// Calling function. ` ` ` `int` `result = otherNumber(A, Lcm, Hcf); ` ` ` ` ` `cout << ` `"B = "` `<< result; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find other number from given ` `// HCF and LCM ` `class` `GFG{ ` ` ` `// Function that will calculates ` `// the zeroes at the end ` `static` `int` `otherNumber(` `int` `A, ` `int` `Lcm, ` `int` `Hcf) ` `{ ` ` ` `return` `(Lcm * Hcf) / A; ` `} ` ` ` `// Driver code ` `public` `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); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 program to find other ` `# number from given HCF and LCM ` ` ` `# Function that will calculates ` `# the zeroes at the end ` `def` `otherNumber(a, Lcm, Hcf): ` ` ` `return` `(Lcm ` `*` `Hcf) ` `/` `/` `A ` ` ` `# Driver code ` `A ` `=` `8` `; Lcm ` `=` `8` `; Hcf ` `=` `1` ` ` `# Calling function ` `result ` `=` `otherNumber(A, Lcm, Hcf) ` `print` `(` `"B ="` `, result) ` ` ` `# This code is contributed ` `# by Shrikant13 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find other number ` `// from given HCF and LCM ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function that will calculates ` `// the zeroes at the end ` `static` `int` `otherNumber(` `int` `A, ` `int` `Lcm, ` ` ` `int` `Hcf) ` `{ ` ` ` `return` `(Lcm * Hcf) / A; ` `} ` ` ` `// Driver code ` `static` `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 ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find other number ` `// from given HCF and LCM ` ` ` `// Function that will calculates ` `// the zeroes at the end ` `function` `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 ` |

*chevron_right*

*filter_none*

**Output:**

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.

## Recommended Posts:

- 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
- LCM and HCF of fractions
- Given GCD G and LCM L, find number of possible pairs (a, b)
- Program to find GCD or HCF of two numbers
- Program to find HCF iteratively
- Program to find HCF (Highest Common Factor) of 2 Numbers
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Find HCF of two numbers without using recursion or Euclidean algorithm
- Find any pair with given GCD and LCM
- Find two numbers with given sum and maximum possible LCM
- Find the ratio of LCM to GCD of a given Array
- LCM of digits of a given number
- HCF of array of fractions (or rational numbers)
- Find the other end point of a line with given one end and mid
- Program to find LCM of two numbers
- Find LCM of rational numbers
- Program to find LCM of 2 numbers without using GCD
- Find three integers less than or equal to N such that their LCM is maximum
- Program to find LCM of two Fibonnaci 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 contribute@geeksforgeeks.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.