Simple Math 3

AtCoder
IDarc111_e
Time2000ms
Memory256MB
Difficulty
In this problem, you will be given $T$ test cases for each input. Given integers $A$, $B$, $C$, and $D$, find the number of positive integers $i$ satisfying the following condition: * None of the integers between $A + B \times i$ and $A + C \times i$ (inclusive) is a multiple of $D$. We can prove from the constraints that the count is finite. ## Constraints * $1 \leq T \leq 10{,}000$ * $1 \leq A < D$ * $0 \leq B < C < D$ * $2 \leq D \leq 10^8$ ## Input Input is given from Standard Input in the following format: $T$ $A_1$ $B_1$ $C_1$ $D_1$ $:$ $A_T$ $B_T$ $C_T$ $D_T$ [samples]
Samples
Input #1
2
3 1 2 5
99 101 103 105
Output #1
1
25

The pairs $(A + B \times i, A + C \times i)$ for the first case are listed below. We can see that only $i = 3$ satisfies the condition.

*   $i = 1: (4, 5)$
*   $i = 2: (5, 7)$
*   $i = 3: (6, 9)$
*   $i = 4: (7, 11)$
*   $i = 5: (8, 13)$
*   $:$
API Response (JSON)
{
  "problem": {
    "name": "Simple Math 3",
    "description": {
      "content": "In this problem, you will be given $T$ test cases for each input. Given integers $A$, $B$, $C$, and $D$, find the number of positive integers $i$ satisfying the following condition: *   None of the i",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc111_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In this problem, you will be given $T$ test cases for each input.\nGiven integers $A$, $B$, $C$, and $D$, find the number of positive integers $i$ satisfying the following condition:\n\n*   None of the i...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments