GCD of Two Numbers Problem
GCD of Two Numbers Problem — ExecCode School DSA Practice
Solve the GCD of Two Numbers problem on ExecCode. Free online school DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Find the Greatest Common Divisor (GCD) of two numbers a and b. The GCD of two integers is the largest positive integer that divides both of them without a remainder. We use the Euclidean Algorithm: gcd(a, b) = gcd(b, a % b).
Examples
Input a = 48, b = 18; Output 6. Input a = 10, b = 0; Output 10. Input a = 105, b = 252; Output 21
Constraints
0 <= a, b <= 10^9 At least one of a or b is non-zero
Practice GCD of Two Numbers free on ExecCode. Browse DSA problems, topic map, and placement guides.