Author : shailesh_2004
Required Knowledge : Bit Manipulation
Time Complexity :
Editorialist : shailesh_2004
Our task is to maximize the value of the given expression.
Let's consider each bit and decide the bit value of at that position.
Compare the values obtained by putting and
separately in that position in the expression by taking only that position's values of other varibles.
Let be the bit values at a certain position in
respectively.
If we put at that position in
, the value is
^
^
^
If we put at that position in
, the value is
^
^
^
If , then we have two choices of choosing
or
at that position.
Otherwise, we need to put the bit that maximizes the value i.e., we have only one choice based on which is higher among and
.
For each bit, we check and
and apply basic Math to get the number of values possible for
.
// Author : Shailesh
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define endl "\n"
#define mod 1000000007
#define tot(a) a.begin(),a.end()
#define minii *min_element
#define maxii *max_element
// ------------------------------------------------------------------------------------
void solve()
{
ll a,b,c;
cin>>a>>b>>c;
ll i;
ll ans=1;
for(i=0;i<30;i++)
{
ll aa=0,bb=0,cc=0;
if((1<<i)&(a))aa=(1<<i);
if((1<<i)&(b))bb=(1<<i);
if((1<<i)&(c))cc=(1<<i);
ll x=0;
ll xx=(1<<i);
if((((aa&bb)^(cc&xx))+((bb|cc)&(aa|xx))+((cc^aa)|(bb^xx)))==
(((aa&bb)^(cc&x))+((bb|cc)&(aa|x))+((cc^aa)|(bb^x))))ans*=2;
}
cout<<ans<<endl;
}
// ------------------------------------------------------------------------------------
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll t;cin>>t;while(t--)
solve();
return 0;
}