XOR__ADD EDITORIAL

PROBLEM LINK

** PREREQUISITES**
MATH,BIT MANIPULATION

EXPLANATION:

We are Given a number ‘A’ we just need to find the smallest B such that A+B = A ⊕ B
Since it is given that B must be smallest we just need to find the only unset bit in A which will be the answer, since unsetbit + setbit = unsetbit ⊕ setbit

CODE:

#include<bits/stdc++.h>
using namespace std;

void solve()
{
  long a; 
  cin >> a;
  long cnt = 0;
  while (a % 2 != 0)
  {
    cnt++;
    a /= 2;
  }
  long one=1;
  long ans = (one << cnt);
  cout << ans<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  int t;
  cin >> t;

  for (int tt = 1; tt <= t; tt++)
  {
    // cout << "Case #" << tt << ": ";
    solve();
  }

}