#P9645. [SNCPC2019] K-hour Clock

    ID: 8982 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>数学2019Special JudgeO2优化陕西XCPC

[SNCPC2019] K-hour Clock

题目描述

A kk-hour clock is a day keeping method which follows the rules below:

  • A day is divided into kk hours, where the ii-th hour is called the (i1)(i-1) o' clock;
  • If it's xx o'clock now, it will be (x+1)(x+1) o'clock after 11 hour if 0x<k10 \le x < k - 1;
  • If it's (k1)(k - 1) o'clock now, it will be 00 o'clock after 11 hour.

We know that it's xx o'clock now, and after yy hours it will be zz o'clock. What's the value of kk?

输入格式

There are multiple test cases. The first line of the input is an integer TT (about 10510^5), indicating the number of test cases. For each test case:

The first and only line contains three integers xx, yy and zz (0x,z1090 \le x, z \le 10^9, 1y1091 \le y \le 10^9).

输出格式

For each test case output one line containing one integer, indicating the value of kk. Note that there must be 1k2×1091 \le k \le 2 \times 10^9. If there are multiple valid answers, you can print any of them; If there is no valid answer, print -1 (without quotes) instead.

题目大意

给定三个数 x,y,zx,y,z,求一个满足 k>x,k>zk>x,k>z 的数 kk,使得 x+yz(modk)x+y\equiv z\pmod k

4
11 18 5
3 49 4
1 9 1
1 3 10
12
24
3
-1