# NT01 - Editorial

Difficulty

Easy-medium

Problem

Solution

Let’s assume that there are two non-negative integers x and y such that x + y = a and x\oplus y = b . Now we can say the following things-

• We know that x + y = x\oplus y + 2(x & y) or (x & y) = (a - b)/2. Now as x & y must be a non-negative integer, therefore can say that a\ge b and (a-b)%2 = 0.
• Lets assume that b_1 and b_2 are any two boolean variables. Note that b_1 & b_2 and b_1\oplus b_2 can’t be 1 simultaneously (you can verify this by looking at their truth tables), this means that no two corresponding bits of x & y and x\oplus y are simultaneously set, this implies that (x & y) & (x\oplus y) = 0 or ((a - b)/2) & b = 0.

So for given a and b, we just have to check if they satisfy the above two conditions or not.

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int T;
cin>>T;
while(T--)
{
ll a,b;
cin>>a>>b;
if((a<b) || (a-b)%2){
cout<<"NO\n";
}
else{
ll var=(a-b)/2;
if(var&b)
cout<<"NO\n";
else
cout<<"YES\n";
}
}
return 0;
}