Codeforces Round #752 (Div. 2) D. Moderate Modular Mode(思维)

原题链接
题意:让你选出一个n,使得对于给出的x,y,n % x = y % n。
思路:首先对于x > y,易得出直接输出 x + y即可。
我们讨论x <= y时的情况。
首先直接列式子列了半天也没列出个所以然来,因为式子里面有%不好处理,于是我们把问题转化为x轴上的问题。
再推出三者大小关系:因为n % x = y % n且x <= y,那么x <= n <= y。
于是我们把问题转化到x轴上,这时画图易得结论~
在这里插入图片描述
因此我们取这个px ~ y的中点即可使得 n % x = y % n~
也就是y - y % x / 2。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <queue>

using namespace std;
#define endl '\n'
#define int long long
void solve(){
    int x,y;
    cin >> x >> y;
    if (x > y){
        cout << x + y << endl;
        return;
    }
    cout << y - y % x / 2 << endl;
}
signed main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值