

翻译:
谁有两个偶数𝑥和𝑦。帮助他找到一个整数𝑛,使1≤𝑛≤2⋅1018,且𝑛mod𝑥=𝑦mod𝑛。这里,𝑎mod𝑏表示𝑎除以𝑏后的余数。如果有多个这样的整数,则输出any。可以证明,在给定的约束条件下,这样的整数总是存在的。
输入
 第一行包含一个整数𝑡(1≤𝑡≤105)——测试用例的数量。
每个测试用例的第一行也是唯一一行包含两个整数𝑥和𝑦(2≤𝑥,𝑦≤109,都是偶数)。
输出
 对于每个测试用例,请打印满足命题条件的单个整数𝑛(1≤𝑛≤2⋅1018)。如果有多个这样的整数,则输出any。可以证明,在给定的约束条件下,这样的整数总是存在的。
例子
 inputCopy
 4
 4 8
 4个2
 420 420
 69420 42068
 outputCopy
 4
 10
 420
 9969128
 请注意
 在第一个测试用例中,4mod4=8mod4=0。
在第二个测试用例中,10mod4=2mod10=2。
在第三个测试用例中,420mod420=420mod420=0。
思路:
很明显分为两种情况,x>=y,x<y。当x>=y的时候,n可以直接取得k*x+y,这样两边都是y;另一种情况就比较麻烦,因为n mod x,所以最终值肯定是小于x的,y mod n,所以我们要从y%x入手,y%x=y-y/x*x,我们可以取整数 p,使得 p * x <= y,那么此时 p * x % x = 0,y % (p * x) = y - p * x,
 由于 y 和 x 都是偶数,所以 y - p * x 一定也是一个偶数,
 我们只需取 [p * x, y] 的中值即可,
 也就是说 n = y - (y - p * x) / 2,
 换句话说,此时 y % (p * x) = y - p * x 等价于 y % x,那么 n = y - y % x / 2
代码:
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<numeric>
using namespace::std;
typedef long long  ll;
int n,t;
ll x,y;
void solv(){
    cin>>x>>y;
    if (y<x) {
        printf("%lld\n",x+y);
    }
    else if (x==y){
        printf("%lld\n",x);
    }
    else{
        printf("%lld\n",(y/x*x+y)/2);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    cin>>t;
    while (t--) {
        solv();
    }
    return 0;
}
 
  












![[附源码]Python计算机毕业设计SSM考勤管理系统(程序+LW)](https://img-blog.csdnimg.cn/361e94cb3715465597ada5cfab386e4b.png)




![[附源码]计算机毕业设计springboot万佳商城管理系统](https://img-blog.csdnimg.cn/a3ef5aa99c894abeaf42fad8b9b4521a.png)

