Mínimo Común Denominador (LCD)

El mínimo común denominador o mínimo común denominador es el mínimo común múltiplo de los denominadores de un conjunto de fracciones.
 

Denominador común : cuando los denominadores de dos o más fracciones son iguales. 
El mínimo común denominador es el más pequeño de todos los denominadores comunes. 
¿Por qué necesitamos LCD
Simplifica la suma, la resta y la comparación de fracciones.
El denominador común se puede evaluar simplemente multiplicando los denominadores. En este caso, 3 * 6 = 18
 

Pero ese puede no ser siempre el mínimo común denominador, como en este caso LCD = 6 y no 18. LCD es en realidad MCM de denominadores.
Ejemplos: 
 

LCD for fractions 5/12 and 7/15 is 60.
We can write both fractions as 25/60 and
28/60 so that they can be added and 
subtracted easily.

LCD for fractions 1/3 and 4/7 is 21.

Problema de ejemplo: dadas dos fracciones, encuentra su suma usando el mínimo común dominador.
Ejemplos
 

Input :  1/6  +  7/15    
Output : 19/30
         Explanation : LCM of 6 and 15 is 30. 
         So, 5/30  +  14/30 = 19/30 
Input :  1/3  +  1/6
Output : 3/6
         Explanation : LCM of 3 and 6 is 6. 
         So, 2/6  +  1/6 = 3/6

Nota* Estas respuestas se pueden simplificar aún más mediante la cancelación anómala. 
 

C++

// C++ Program to determine
// LCD of two fractions and
// Perform addition on fractions
#include <iostream>
using namespace std;
 
// function to calculate gcd
// or hcf of two numbers.
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
 
// function to calculate
// lcm of two numbers.
int lcm(int a, int b)
{
    return (a * b) / gcd(a, b);
}
 
void printSum(int num1, int den1,
              int num2, int den2)
{
    // least common multiple
    // of denominators LCD
    // of 6 and 15 is 30.
    int lcd = lcm(den1, den2);
 
    // Computing the numerators for LCD:
    // Writing 1/6 as 5/30 and 7/15 as
    // 14/30
    num1 *= (lcd / den1);
    num2 *= (lcd / den2);
 
    // Our sum is going to be res_num/lcd
    int res_num = num1 + num2;
    cout << res_num << "/" << lcd;
}
 
// Driver Code
int main()
{
    // First fraction is 1/6
    int num1 = 1, den1 = 6;
 
    // Second fraction is 7/15
    int num2 = 7, den2 = 15;
 
    printSum(num1, den1, num2, den2);
    return 0;
}

Java

// Java Program to determine LCD of two
// fractions and Perform addition on
// fractions
public class GFG {
     
    // function to calculate gcd or
    // hcf of two numbers.
    static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
             
        return gcd(b % a, a);
    }
     
    // function to calculate lcm of
    // two numbers.
    static int lcm(int a, int b)
    {
        return (a * b) / gcd(a, b);
    }
     
    static void printSum(int num1, int den1,
                         int num2, int den2)
    {
         
        // least common multiple of
        // denominators LCD of 6 and 15
        // is 30.
        int lcd = lcm(den1, den2);
     
        // Computing the numerators for LCD:
        // Writing 1/6 as 5/30 and 7/15 as
        // 14/30
        num1 *= (lcd / den1);
        num2 *= (lcd / den2);
     
        // Our sum is going to be res_num/lcd
        int res_num = num1 + num2;
         
        System.out.print( res_num + "/" + lcd);
    }
         
    // Driver code
    public static void main(String args[])
    {
         
        // First fraction is 1/6
        int num1 = 1, den1 = 6;
 
        // Second fraction is 7/15
        int num2 = 7, den2 = 15;
 
        printSum(num1, den1, num2, den2);
    }
}
 
// This code is contributed by Sam007.

Python3

# python Program to determine
# LCD of two fractions and
# Perform addition on fractions
 
# function to calculate gcd
# or hcf of two numbers.
def gcd(a, b):
     
    if (a == 0):
        return b
    return gcd(b % a, a)
 
 
# function to calculate
# lcm of two numbers.
def lcm(a, b):
     
    return (a * b) / gcd(a, b)
 
 
def printSum(num1, den1,
                  num2, den2):
                 
    # least common multiple
    # of denominators LCD
    # of 6 and 15 is 30.
    lcd = lcm(den1, den2);
     
    # Computing the numerators
    # for LCD: Writing 1/6 as
    # 5/30 and 7/15 as 14/30
    num1 *= (lcd / den1)
    num2 *= (lcd / den2)
 
    # Our sum is going to be
    # res_num/lcd
    res_num = num1 + num2;
    print( int(res_num) , "/" ,
                       int(lcd))
 
# Driver Code
# First fraction is 1/6
num1 = 1
den1 = 6
 
# Second fraction is 7/15
num2 = 7
den2 = 15
printSum(num1, den1, num2, den2);
 
# This code is contributed
# by Sam007

C#

// C# Program to determine LCD of two
// fractions and Perform addition on
// fractions
using System;
 
class GFG {
 
    // function to calculate gcd or
    // hcf of two numbers.
    static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
             
        return gcd(b % a, a);
    }
     
    // function to calculate lcm of
    // two numbers.
    static int lcm(int a, int b)
    {
        return (a * b) / gcd(a, b);
    }
     
    static void printSum(int num1, int den1,
                         int num2, int den2)
    {
         
        // least common multiple of
        // denominators LCD of 6 and 15
        // is 30.
        int lcd = lcm(den1, den2);
     
        // Computing the numerators for LCD:
        // Writing 1/6 as 5/30 and 7/15 as
        // 14/30
        num1 *= (lcd / den1);
        num2 *= (lcd / den2);
     
        // Our sum is going to be res_num/lcd
        int res_num = num1 + num2;
         
        Console.Write( res_num + "/" + lcd);
    }
         
    // Driver code
    public static void Main ()
    {
         
        // First fraction is 1/6
        int num1 = 1, den1 = 6;
 
        // Second fraction is 7/15
        int num2 = 7, den2 = 15;
 
        printSum(num1, den1, num2, den2);
    }
}
 
// This code is contributed by Sam007.

PHP

<?php
// PHP Program to determine
// LCD of two fractions and
// Perform addition on fractions
 
// function to calculate gcd
// or hcf of two numbers.
function gcd($a,$b)
{
    if ($a == 0)
        return $b;
    return gcd($b % $a, $a);
}
 
// function to calculate
// lcm of two numbers.
function lcm($a,$b)
{
    return ($a * $b) / gcd($a, $b);
}
 
function printSum($num1, $den1,
                  $num2, $den2)
{
    // least common multiple
    // of denominators
    // LCD of 6 and 15 is 30.
    $lcd = lcm($den1, $den2);
 
    // Computing the numerators for LCD:
    // Writing 1/6 as 5/30 and 7/15 as
    // 14/30
    $num1 *= ($lcd / $den1);
    $num2 *= ($lcd / $den2);
 
    // Our sum is going to be res_num/lcd
    $res_num = $num1 + $num2;
    echo $res_num . "/" . $lcd;
}
    // Driver Code
    // First fraction is 1/6
    $num1 = 1;
    $den1 = 6;
 
    // Second fraction is 7/15
    $num2 = 7;
    $den2 = 15;
 
    printSum($num1, $den1, $num2, $den2);
 
// This code is contributed by Sam007.
?>

Javascript

<script>
// javascript Program to determine LCD of two
// fractions and Perform addition on
// fractions
 
    // function to calculate gcd or
    // hcf of two numbers.
    function gcd(a , b)
    {
        if (a == 0)
            return b;
 
        return gcd(b % a, a);
    }
 
    // function to calculate lcm of
    // two numbers.
    function lcm(a , b)
    {
        return (a * b) / gcd(a, b);
    }
 
    function printSum(num1 , den1 , num2 , den2)
    {
 
        // least common multiple of
        // denominators LCD of 6 and 15
        // is 30.
        var lcd = lcm(den1, den2);
 
        // Computing the numerators for LCD:
        // Writing 1/6 as 5/30 and 7/15 as
        // 14/30
        num1 *= (lcd / den1);
        num2 *= (lcd / den2);
 
        // Our sum is going to be res_num/lcd
        var res_num = num1 + num2;
 
        document.write(res_num + "/" + lcd);
    }
 
    // Driver code
     
        // First fraction is 1/6
        var num1 = 1, den1 = 6;
 
        // Second fraction is 7/15
        var num2 = 7, den2 = 15;
 
        printSum(num1, den1, num2, den2);
 
// This code is contributed by todaysgaurav
</script>

Producción : 
 

19/30

Complejidad de tiempo: O(log(max(deno1,deno2))) 
Espacio auxiliar: O(log(max(deno1,deno2)))

Este artículo es una contribución de Aarti_Rathi y Shubham Rana . Si te gusta GeeksforGeeks y te gustaría contribuir, también puedes escribir un artículo usando write.geeksforgeeks.org o enviar tu artículo por correo a review-team@geeksforgeeks.org. Vea su artículo que aparece en la página principal de GeeksforGeeks y ayude a otros Geeks.
Escriba comentarios si encuentra algo incorrecto o si desea compartir más información sobre el tema tratado anteriormente.
 

Publicación traducida automáticamente

Artículo escrito por GeeksforGeeks-1 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 *