Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/rekursiya-ekub-topish

GCD (Euclidean algorithm)

Easy 1000 ms 64 MB 28%
Share

You are given two positive integers $a$ and $b$. Using the recursive Euclidean algorithm, find their greatest common divisor (GCD).

The Euclidean algorithm:
$$\text{GCD}(a, 0) = a$$
$$\text{GCD}(a, b) = \text{GCD}(b, a \pmod b) \quad (b > 0)$$

In every call the pair is replaced by the second number and the remainder; when the second number is 0, the first is the answer

Input

One line with two integers $a$ and $b$ separated by a space ($1 \le a, b \le 10^9$).

Output

The GCD of $a$ and $b$.

Note

$1 \le a, b \le 10^9$

Examples

Input #1
24 36
Output #1
12
Input #2
17 13
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.