Advertisement
a53

Xorstanta

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