GCD Subtraction

AtCoder
IDarc159_b
Time2000ms
Memory256MB
Difficulty
We have variables $a$ and $b$. Initially, $a=A$ and $b=B$. Takahashi will repeat the following operation while both $a$ and $b$ are greater than or equal to $1$. * Let $g$ be the greatest common divisor of $a$ and $b$, and replace $a$ and $b$ with $a-g$ and $b-g$, respectively. How many times will he perform the operation? ## Constraints * $1 \leq A,B \leq 10^{12}$ * $A$ and $B$ are integers. ## Input The input is given from Standard Input in the following format: $A$ $B$ [samples]
Samples
Input #1
15 9
Output #1
2

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

*   Let $g=3$, and replace $a$ and $b$ with $12(=15-3)$ and $6(=9-3)$, respectively.
*   Let $g=6$, and replace $a$ and $b$ with $6(=12-6)$ and $0(=6-6)$, respectively. $b$ is no longer greater than or equal to $1$, so the iteration terminates.
Input #2
1 1
Output #2
1
Input #3
12345678910 10987654321
Output #3
36135
API Response (JSON)
{
  "problem": {
    "name": "GCD Subtraction",
    "description": {
      "content": "We have variables $a$ and $b$. Initially, $a=A$ and $b=B$. Takahashi will repeat the following operation while both $a$ and $b$ are greater than or equal to $1$. *   Let $g$ be the greatest common di",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc159_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have variables $a$ and $b$. Initially, $a=A$ and $b=B$.\nTakahashi will repeat the following operation while both $a$ and $b$ are greater than or equal to $1$.\n\n*   Let $g$ be the greatest common di...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments