题解:CF1790E Vlad and a Pair of Numbers

· · 题解

卡我题单上限我已急哭。

容易知道 a+b=(a\operatorname{xor}b)+ 2(a\operatorname{and}b)。

所以我们需要对于给定的 x 构造 a,b 使得 a\operatorname{xor}b=2(a\operatorname{and}b)=x。

显然有解必须要求 x 是偶数的同时,x 右移一位的结果和 x 不能有位置同时是 1,因为异或面对能够让与得到 1 的情况,也就是同时是 1 的时候,返回的一定是 0。

其余情况,我们现在已知了 A=a\operatorname{and}b 和 B=a\operatorname{xor}b,我们直接要求一个数字是 A,另一个数字是 A+B 显然是一个合法解。

如果这个解不满足条件,那么容易得知局面不合法,故也不需要另外分讨。

// LUOGU_RID: 143902086
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;cin>>t;
    while(t--){
        int x,a,b;cin>>x,a=x/2,b=3*a;
        if((a^b)==x)cout<<a<<' '<<b<<'\n';
        else puts("-1");
    }
    return 0;
}
// 我不知道该怎么将这本日记交给她。
// 我究竟能为沙耶做些什么?
// 我不知道。
// 因为我没有失去过重要的人。