Advertisement
Brick99

WCI PEG Xor

May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iomanip>
  5. #include <cmath>
  6. #include <stdio.h>
  7. #include <utility>
  8.  
  9. using namespace std;
  10.  
  11. int xor2(int a)
  12. {
  13.     if ( (a+1) % 4 == 0 ) return 1;
  14.     else if ( (a+1) % 4 == 1 ) return a+1;
  15.     else if ( (a+1) % 4 == 2 ) return 0;
  16.     else return a;
  17. }
  18.  
  19. int xor1(int a, int b){ return xor2(b) ^ xor2(a-1); }
  20.  
  21. int main()
  22. {
  23.     int n;
  24.     cin>>n;
  25.     while (n--)
  26.     {
  27.         int a,b;
  28.         cin>>a>>b;
  29.  
  30.         cout<<xor1(a,b)<<endl;
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement