Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!
ALGOR Contest: Round #3 (Weekly Sprint)
Problem B · 100 points · ICPC rules

~/algor $ cat contests/round-3/B

B. Euclidean algorithm steps

1000 ms 64 MB

Two positive integers $a$ and $b$ are given. In the Euclidean algorithm, at each step the pair $(a, b)$ is replaced by the pair $(b, a \bmod b)$; when $b = 0$, $a$ is the GCD of the original numbers. Find the GCD and the number of steps the algorithm performs.

A staircase of pairs: at each step the second number and the remainder; it ends with zero

Input

One line with two positive integers: $a$ and $b$.

Output

Two integers separated by a space: the GCD and the number of steps.

Note

$1 \le a, b \le 10^{18}$

Examples

Input #1
48 18
Output #1
6 3
Input #2
7 7
Output #2
7 1

Sign in to submit a solution

Signing up is free and takes a minute.