Encuentre el otro número cuando se dan MCM y HCF

Dado un número A y MCM y HCF La tarea es determinar el otro número B.
Ejemplos: 
 

Input: A = 10, Lcm = 10, Hcf = 50.
Output: B = 50

Input: A = 5, Lcm = 25, Hcf = 4.
Output: B = 20

Fórmula:- 
 

A * B = MCM * HCF 
B = (MCM * HCF)/A
Ejemplo: A = 15, B = 12 
HCF = 3, MCM = 60 
Podemos ver que 3 * 60 = 15 * 12.
¿Cómo funciona esta fórmula?  
Dado que HCF divide ambos números, dejemos. 
A = HCF * x 
B = HCF * y
Tenga en cuenta que x e y no son factores comunes, por lo que MCM debe incluir HCF, x e y. 
Entonces podemos concluir. 
LCM = HCF * x * y
Entonces LCM * HCF = HCF * x * y * HCF que es igual a A * B

A continuación se muestra la implementación del enfoque anterior: 
 

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;
}

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);
 
}
}

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

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

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

Javascript

<script>
 
// Javascript 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
 
    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>
Producción: 

B = 1

 

Complejidad de tiempo: O(1)

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por Naman_Garg y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *