Greatest common divisor · Máximo divisor comum
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 comum
O MDC de dois números é o maior inteiro que divide ambos. O algoritmo de Euclides é lindamente curto: enquanto b não for 0, substitua o par (a, b) por (b, a % b). Quando b chegar a 0, a será a resposta.
Complete int gcd(int a, int b) to return the greatest common divisor of a and · e b. Euclid's method: repeatedly replace (a, b) with (b, a % b) until b is 0. · Complete int gcd(int a, int b) para retornar o máximo divisor comum de a e b. Método de Euclides: substitua repetidamente (a, b) por (b, a % b) até b ser 0.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.