[SNCPC2019] K-hour Clock
题面翻译
给定三个数
x
,
y
,
z
x,y,z
x,y,z,求一个满足
k
>
x
,
k
>
z
k>x,k>z
k>x,k>z 的数
k
k
k,使得
x
+
y
≡
z
(
m
o
d
k
)
x+y\equiv z\pmod k
x+y≡z(modk)。
题目描述
A k k k-hour clock is a day keeping method which follows the rules below:
- A day is divided into k k k hours, where the i i i-th hour is called the ( i − 1 ) (i-1) (i−1) o’ clock;
- If it’s x x x o’clock now, it will be ( x + 1 ) (x+1) (x+1) o’clock after 1 1 1 hour if 0 ≤ x < k − 1 0 \le x < k - 1 0≤x<k−1;
- If it’s ( k − 1 ) (k - 1) (k−1) o’clock now, it will be 0 0 0 o’clock after 1 1 1 hour.
We know that it’s x x x o’clock now, and after y y y hours it will be z z z o’clock. What’s the value of k k k?
输入格式
There are multiple test cases. The first line of the input is an integer T T T (about 1 0 5 10^5 105), indicating the number of test cases. For each test case:
The first and only line contains three integers x x x, y y y and z z z ( 0 ≤ x , z ≤ 1 0 9 0 \le x, z \le 10^9 0≤x,z≤109, 1 ≤ y ≤ 1 0 9 1 \le y \le 10^9 1≤y≤109).
输出格式
For each test case output one line containing one integer, indicating the value of
k
k
k. Note that there must be
1
≤
k
≤
2
×
1
0
9
1 \le k \le 2 \times 10^9
1≤k≤2×109. If there are multiple valid answers, you can print any of them; If there is no valid answer, print -1
(without quotes) instead.
样例 #1
样例输入 #1
4
11 18 5
3 49 4
1 9 1
1 3 10
样例输出 #1
12
24
3
-1
代码内容
// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//队列
// #include <queue>//堆/优先队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll x,y,z;
cin>>x>>y>>z;
if(x+y-z<0)
cout<<-1<<endl;
else if(x+y==z)
cout<<z+1<<endl;
else
{
if(x+y-z<=x||x+y-z<=z)
cout<<-1<<endl;
else
cout<<x+y-z<<endl;
}
}
return 0;
}