-
-
Save parzibyte/6a7acac4a0daa815f6c8c21069c7d16f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
// https://parzibyte.me/blog | |
public static void main(String[] args) { | |
int a = 10; | |
int b = 15; | |
int mcm = minimoComunMultiplo(a, b); | |
System.out.printf("El mínimo común múltiplo de %d y %d es %d\n", a, b, mcm); | |
} | |
// Vamos a necesitar esta fórmula para calcular el mínimo común múltiplo | |
public static int maximoComunDivisor(int a, int b) { | |
int temporal;//Para no perder b | |
while (b != 0) { | |
temporal = b; | |
b = a % b; | |
a = temporal; | |
} | |
return a; | |
} | |
public static int minimoComunMultiplo(int a, int b) { | |
// Y ahora aplicamos la fórmula que dice: | |
// MCM(a, b) = (a * b) / MCD(a, b) | |
return (a * b) / maximoComunDivisor(a, b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment