K-hour Clock

[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+yz(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) (i1) 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 0x<k1;
  • If it’s ( k − 1 ) (k - 1) (k1) 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 0x,z109, 1 ≤ y ≤ 1 0 9 1 \le y \le 10^9 1y109).

输出格式

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 1k2×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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值