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

~/algor $ cat problems/while-ekub-ayirish-usulida

GCD by subtraction

Easy 1000 ms 64 MB 32%
Share

Two positive integers $a$ and $b$ are given. While the numbers are not equal, the smaller one is subtracted from the larger one:

$$a \gt b \Rightarrow a = a - b, \qquad b \gt a \Rightarrow b = b - a$$

When the numbers become equal, their value is the greatest common divisor (GCD) of $a$ and $b$. Find the GCD and the number of subtractions performed (for example, $(12; 18) \to (12; 6) \to (6; 6)$: GCD $6$, $2$ subtractions).

Finding the GCD by repeatedly subtracting the smaller number from the larger

Input

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

Output

One line with two integers separated by a space: the GCD and the number of subtractions.

Note

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

Examples

Input #1
12 18
Output #1
6 2
Input #2
7 7
Output #2
7 0

Sign in to submit a solution

Signing up is free and takes a minute.