AtCoder Regular Contest 111
翻译中…
Problem Statement
翻译中…
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
翻译中…
Output
翻译中…
Print $T$ lines.
翻译中…
The $i$-th line should contain the answer for the $i$-th case ($A_i$, $B_i$, $C_i$, $D_i$).
翻译中…
样例
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)$
- $:$
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。