No.2767 Add to Divide
タグ : / 解いたユーザー数 115
作問者 :
srjywrdnprkt
/ テスター :
👑 Problem Statement
You are given positive integers $A$ , $B$. It is guaranteed that $A \leq B$.
Determine whether there exists a non-negative integer $X$ such that $B+X$ is a multiple of $A+X$, and if one exists, find the minimum such value.
You are given $T$ test cases; solve each of them.
Input
$T$ $\rm case_1$ $\vdots$ $\rm case_T$Here, $\rm case_i$ denotes the $i$-th test case. Each test case is given in the following format.
$A\ B$
All inputs are integers and satisfy the following constraints.
- $1 \leq T \leq 100$
- $1 \leq A \leq B \leq 10^9$
Output
If no non-negative integer $X$ satisfying the condition exists, print -1; otherwise, print the minimum such $X$.
Print $T$ lines; the $i$-th line should contain the answer to the $i$-th test case.
Sample
Sample 1
Input
4 11 23 2 3 8 16 4394 993298361
Output
1 -1 0 331093595
For the $1$-st test case, setting $X=1$ makes $B+X=24$ a multiple of $A+X=12$. $X$ cannot be made any smaller, so $1$ is the answer.
For the $2$-nd test case, no $X$ satisfying the condition exists.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。