#ARC159B. [ARC159B] GCD Subtraction

[ARC159B] GCD Subtraction

Score : 400400 points

Problem Statement

We have variables aa and bb. Initially, a=Aa=A and b=Bb=B.

Takahashi will repeat the following operation while both aa and bb are greater than or equal to 11.

  • Let gg be the greatest common divisor of aa and bb, and replace aa and bb with aga-g and bgb-g, respectively.

How many times will he perform the operation?

Constraints

  • 1A,B10121 \leq A,B \leq 10^{12}
  • AA and BB are integers.

Input

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

AA BB

Output

Print the answer.

15 9
2

We start with a=15,b=9a=15,b=9 and perform the following.

  • Let g=3g=3, and replace aa and bb with 12(=153)12(=15-3) and 6(=93)6(=9-3), respectively.
  • Let g=6g=6, and replace aa and bb with 6(=126)6(=12-6) and 0(=66)0(=6-6), respectively. bb is no longer greater than or equal to 11, so the iteration terminates.
1 1
1
12345678910 10987654321
36135