GCD of two numbers
128 megabytes
Find the greatest common divisor (GCD) of two non-negative integers.
\gcd(a, b) = \begin{cases}
a, & b = 0 \\
b, & a = 0 \\
\gcd(a \bmod b,\, b), & a \ge b \\
\gcd(a,\, b \bmod a), & a < b
\end{cases}
Input
Two integers a and b (0 \leq a,\, b \leq 2 \cdot 10^9).
Output
Print the greatest common divisor of a and b.