Numbers and arithmetic · Python exercise
Compute the greatest common divisor of two positive integers.
Read two positive integers and print their greatest common divisor (GCD). The GCD is the largest integer that divides both values.
Example 1
Input
12 18
Output
6
Example 2
Input
7 13
Output
1
Coprime numbers have a GCD of 1.
How testing works
Your code runs once per test case with that case's standard input. Output is compared after normalising trailing spaces and blank lines at the end. Use input() without a prompt when the exercise expects clean output.
Loading editor…
Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.