🧮

Greatest Common Divisor

Greatest Common Divisor
쉬움 알고리즘 +10pts

Problem

Write a function that returns the greatest common divisor of two numbers.

Examples

Input: gcd(12, 8)
Output: 4

Explanation

이 문제는 **유클리드 호제법(Euclidean Algorithm)**으로 최대공약수를 구하는 방법을 학습합니다. ## 핵심 개념: 최대공약수 (GCD) 최대공약수는 두 수를 모두 나눌 수 있는 가장 큰 수입니다. ### 유클리드 호제법 ```javascript function gcd(a, b) { while (b) { [a, b] = [b, a % b]; } return a; } ``` ### 동작 원리 GCD(a, b) = GCD(b, a % b) - 12와 8의 GCD - GCD(12, 8) → GCD...

View detailed explanation →

Key Concepts

유클리드 호제법 최대공약수 나머지 연산 재귀
Time: O(log(min(a,b))) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.