Greatest common divisor · Plus grand commun diviseur
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.
Plus grand commun diviseur
Le PGCD de deux nombres est le plus grand entier qui les divise tous deux. L'algorithme d'Euclide est magnifiquement court : tant que b n'est pas 0, remplacez la paire (a, b) par (b, a % b). Quand b atteint 0, a est la réponse.
Complete int gcd(int a, int b) to return the greatest common divisor of a and · et b. Euclid's method: repeatedly replace (a, b) with (b, a % b) until b is 0. · Complétez int gcd(int a, int b) pour retourner le plus grand commun diviseur de a et b. Méthode d'Euclide : remplacez répétitivement (a, b) par (b, a % b) jusqu'à ce que b soit 0.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.