Greatest common divisor · Máximo común divisor
Greatest common divisor
The GCD of two numbers is the largest integer that divides both. Euclid's algorithm is beautifully short: while b isn't 0, replace the pair (a, b) with (b, a % b). When b reaches 0, a is the answer.
Máximo divisor común
El MCD de dos números es el entero más grande que los divide a ambos. El algoritmo de Euclides es bellamente sencillo: mientras b no sea 0, reemplace la pareja (a, b) por (b, a % b). Cuando b llega a 0, a es la respuesta.
Complete int gcd(int a, int b) to return the greatest common divisor of a and · y b. Euclid's method: repeatedly replace (a, b) with (b, a % b) until b is 0. · Completa int gcd(int a, int b) para devolver el máximo común divisor de a y b. Método de Euclides: reemplaza repetidamente (a, b) por (b, a % b) hasta que b sea 0.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.