Write a program which finds the greatest common divisor of two natural numbers a and b…
- User
Write a program which finds the greatest common divisor of two natural numbers a and b
Hint
You can use the following observation:
For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y)
Constrants
1 ≤ a, b ≤ 109 Input
a and b are given in a line sparated by a single space.
Output
Output the greatest common divisor of a and b.
Examples
Input
54 20
Output
2
Input
147 105
Output
21
Assistant
a, b = map(int, input().split()) def gcd(x, y): while y != 0: x, y = y, x % y return x print(gcd(a, b))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.