問題一覧 > 通常問題

No.2767 Add to Divide

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 115
作問者 : srjywrdnprkt / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 10634 / 自分の提出
問題文最終更新日: 2024-05-30 20:28:32
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 431 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。