原题链接
题意:让你选出一个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();
}