

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
を で割った余りが となるような正の整数 が存在するか判定し、存在する場合は最小のものを求めてください。
個のテストケースが与えられるので、それぞれに対して答えてください。
制約
- は の倍数でも の倍数でもない
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられます。ただし、 個目 のテストケースにおける の値を とします。
出力
行にわたって出力してください。 行目には、 個目のテストケースに対する答えを出力してください。ただし、条件を満たす が存在しない場合は答えを とします。
入力例 1Copy
2 27 311670611
出力例 1Copy
3 11
この入力例は 個のテストケースからなります。
- 個目: を で割った余りは なので、 で条件を満たします。
- 個目: を で割った余りは なので、 で条件を満たします。
Score: points
Problem Statement
Determine whether there is a positive integer such that the remainder of divided by is . If it exists, find the smallest such .
You will be given test cases to solve.
Constraints
- is neither a multiple of nor a multiple of .
- All input values are integers.
Input
The input is given from Standard Input in the following format, where is the value of in the -th test case :
Output
Print lines. The -th line should contain the answer for the -th test case. If no satisfies the condition, the answer should be .
Sample Input 1Copy
2 27 311670611
Sample Output 1Copy
3 11
This sample input consists of two test cases.
- The first case: The remainder of divided by is , so satisfies the condition.
- The second case: The remainder of divided by is , so satisfies the condition.