Advertisement
mihaimarcel21

Xorstanta

Nov 20th, 2020
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int n, t, sol;
  4. int main()
  5. {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(0);
  8.     cout.tie(0);
  9.     cin>>t;
  10.     while(t--)
  11.     {
  12.         cin>>n;
  13.         sol = 0;
  14.  
  15.         for(int i=0; (1 << i) <= n; i++)
  16.         {
  17.             int A=(n + 1)/(1<<(i + 1));
  18.             int B=(n + 1)%(1<<(i + 1));
  19.             int aux=A*(1 << i);
  20.             aux += max(0, B -= (1 << i));
  21.             if(aux % 2 == 0)
  22.                 sol += (1 << (i + 1));
  23.             else
  24.                 sol += (1 << i);
  25.         }
  26.         cout << sol << '\n';
  27.     }
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement