#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll Xor(ll n)
{
if(n%4==0)
return n;
if(n%4==1)
return 1;
if(n%4==2)
return n+1;
if(n%4==3)
return 0;
}
int main()
{
ll t;
cin>>t;
while(t--)
{
ll l,r;
cin>>l>>r;
if(l==r)
cout<<"0\n";
else
cout<<abs(Xor(r)-Xor(l-1))<<"\n";
}
return 0;
}
↧
How to find XOR of all the elements in given range?
↧