#ABC297D. [ABC297D] Count Subtractions

[ABC297D] Count Subtractions

Score : 400400 points

Problem Statement

You are given positive integers AA and BB.

You will repeat the following operation until A=BA=B:

  • compare AA and BB to perform one of the following two:- if A>BA > B, replace AA with ABA-B;
    • if A<BA < B, replace BB with BAB-A.
  • if A>BA > B, replace AA with ABA-B;
  • if A<BA < B, replace BB with BAB-A.

How many times will you repeat it until A=BA=B? It is guaranteed that a finite repetition makes A=BA=B.

Constraints

  • 1A,B10181 \le A,B \le 10^{18}
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

AA BB

Output

Print the answer.

3 8
4

Initially, A=3A=3 and B=8B=8. You repeat the operation as follows:

  • A,soreplaceA, so replace Bwith with B-A=5,making, making A=3and and B=5$.
  • A,soreplaceA, so replace Bwith with B-A=2,making, making A=3and and B=2$.
  • A>BA>B, so replace AA with AB=1A-B=1, making A=1A=1 and B=2B=2.
  • A,soreplaceA, so replace Bwith with B-A=1,making, making A=1and and B=1$.

Thus, you repeat it four times.

1234567890 1234567890
0

Note that the input may not fit into a 32-bit integer type.

1597 987
15