PROBLEM LINK:
Author: Deepak Chaudhary
Tester: Vikas Yadav
Editorialist: Deepak Chaudhary
DIFFICULTY:
EASY
PREREQUISITES:
PROBLEM:
Find A for given two numbers X and Y such that (A⊕X)+(A⊕Y) will give minimum value.
QUICK EXPLANATION:
For minimum value (A⊕X)+(A⊕Y) can be written as (X ⊕ Y).
EXPLANATION:
Think about addition in base two. Say X = 10101 and Y = 1001. What your operation does is it modifies the bits in your numbers, so if the first bit in X is 1 and the first bit in Y is 1 (as is the case above) you can make both 0 by making that bit 1 in A. This is actually the only way you can decrease the resulting sum, so A = 1 is an answer above.
SOLUTIONS:
Setter's Solution
// Chef and Chefina
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int test_cases;
cin >> test_cases;
while(test_cases--)
{
int a, b;
cin >> a >> b;
cout << (a ^ b) << "\n";
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
}
Tester's Solution
// Chef and Chefina
#include <stdio.h>
int main()
{
int test_cases;
scanf("%d", &test_cases);
while(test_cases--)
{
int x, y;
scanf("%d %d", &x, &y);
printf("%ld\n", x ^ y);
}
return 0;
}