#P10782. 【MX-J1-T2】『FLA - III』Ilumina

    ID: 12042 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学二分Special JudgeO2优化构造梦熊比赛

【MX-J1-T2】『FLA - III』Ilumina

Background

Original problem link: https://oier.team/problems/J1B.

Problem Description

Define X\lfloor X \rfloor as the greatest integer less than or equal to XX. For example, 1.99=1,7=7\lfloor 1.99 \rfloor = 1, \lfloor 7 \rfloor = 7.

There are five positive integers n,m,a,b,cn, m, a, b, c, and it is known that b=anb = \left\lfloor \frac{a}{n} \right\rfloor, c=bmc = \left\lfloor \frac{b}{m} \right\rfloor.

Given the values of aa and cc, find a valid value of bb, or report that no valid value of bb exists.

This problem uses a custom checker. If multiple valid values of bb exist, output any one of them.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, the number of test cases.

For each test case, input one line with two positive integers a,ca, c.

Output Format

For each test case, output one integer on a single line. If no valid value of bb exists, output -1; otherwise output a valid value of bb.

This problem uses a custom checker. If multiple valid values of bb exist, output any one of them.

4
1 1
7 3
23 8
17 23

1
3
-1
-1

Hint

"Sample Explanation #1"

For the first test case, choosing n=1,m=1n = 1, m = 1 yields b=1b = 1.

For the second test case, choosing n=2,m=1n = 2, m = 1 yields b=3b = 3.

For the third and fourth test cases, it can be proven that no valid value of bb exists.

Constraints

Test Point ID a,ca, c \leq Special Property
131 \sim 3 1010 None
464 \sim 6 10310^3
787 \sim 8 101810^{18} Yes
9109 \sim 10 None

Special property: It is guaranteed that for each given a,ca, c, a valid value of bb always exists.

For 100%100\% of the testdata, 1T1051 \leq T \leq 10^5, 1a,c10181 \leq a, c \leq 10^{18}.

July 15, 2024: Added 7 hack testdata cases to Subtask #1.

Translated by ChatGPT 5