GCD
EasyP2Coding
Return the greatest common divisor of two non-negative integers a and b: the largest integer that divides both.
By convention gcd(a, 0) = a, gcd(0, b) = b and gcd(0, 0) = 0.
Example 1
- Input
- a = 12, b = 18
- Output
- 6
Example 2
- Input
- a = 7, b = 13
- Output
- 1
Example 3
- Input
- a = 0, b = 5
- Output
- 5
Constraints
- 0 <= a, b <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.