← Back to challenges

GCD of Two Numbers

PythonHardnumbersmathrecursion

Instructions

Write a function that returns the greatest common divisor (GCD) of two integers.

Examples

gcd(32, 8) ➞ 8

gcd(8, 12) ➞ 4

gcd(17, 13) ➞ 1

Notes

  • Both values will be positive.
  • The GCD is the largest factor that divides both numbers.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: String Pairs