YorKnEz

Untitled

Nov 16th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int T, N, a = 0, b = 0, ax, bx;
  7.  
  8. cin >> T;
  9.  
  10. for (int i = 0; i < T; i++) {
  11. cin >> N;
  12.  
  13. a = 0; b = 0;
  14.  
  15. for (int i = 1; i <= N; i++) {
  16. ax = a^i;
  17. bx = b^i;
  18.  
  19. if (ax + b >= a+ bx) {
  20. a = ax;
  21. } else b = bx;
  22. }
  23.  
  24. cout << a+b << endl;
  25. }
  26.  
  27. return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment