Greatest common 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.
최대공약수(greatest common divisor)
두 수의 최대공약수(GCD)는 두 수를 모두 나눌 수 있는 가장 큰 정수입니다. 유클리드 알고리즘은 매우 간결합니다: b이 0이 아닐 때, 쌍 (a, b)을 (b, a % b)로 교체합니다. b이 0이 되면, a이 정답입니다.
Complete int gcd(int a, int b) to return the greatest common divisor of a and b. Euclid's method: repeatedly replace (a, b) with (b, a % b) until b is 0. · int gcd(int a, int b)를 완성하여 a과 b의 최대공약수를 반환합니다. 유클리드 방법: (a, b)을 (b, a % b)로 반복해서 교체하여 b이 0이 될 때까지 계속합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.