Compute the greatest common divisor (GCD) of two positive integers — the largest number that divides both.
Input
A single line with two positive integers a and b.
Output
The greatest common divisor of a and b.
Compute the greatest common divisor (GCD) of two positive integers — the largest number that divides both.
A single line with two positive integers a and b.
The greatest common divisor of a and b.
Example 1
12 18
6
6 divides both 12 and 18, and nothing larger does.
Example 2
17 5
1
17 and 5 share only 1.
Example 3
100 100
100
The GCD of a number with itself is the number.
Euclid's algorithm: gcd(a, b) = gcd(b, a mod b), and gcd(a, 0) = a.
Repeatedly replace (a, b) with (b, a mod b) until b becomes 0.
Euclid's algorithm: while b is non-zero, replace (a, b) with (b, a mod b); the answer is a.
import math
a, b = map(int, input().split())
print(math.gcd(a, b))
Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.