Codeforces Round #847 (Div. 3) E. Vlad and a Pair of Numbers(位运算)

https://codeforces.com/contest/1790/problem/E

题目大意:

两个正数a和b (a,b>0)。a⊕b=(a+b)/2,  a⊕b==x。

找到任何合适的a和b,或者不存在"-1"。 
inputCopy
6
2
5
10
6
18
36
outputCopy
3 1
-1
13 7
-1
25 11
50 22

异或(xor)⊕ ^
a+b == a^b + 2(a&b) == 2 * x
(a^b)
2 == a^b + 2(a&b)
a^b == 2
(a&b)

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL x;
        cin>>x;
        LL a=x/2,b=x+x/2;
        if((a^b)==x&&x*2==(a+b)) cout<<a<<" "<<b<<endl;
        else cout<<"-1"<<endl;
    }
    return 0;
}
posted @ 2023-01-30 23:16  Vijurria  阅读(89)  评论(0编辑  收藏  举报