题意:
嘤嘤有两个整数 l,r,她想知道区间 [l,r] 所有整数的异或和是多少.
分析:
样例1只有一个数输出1
样例2 1^2=01^10=11=3
样例3 1^2^3=01^10^11=11^11=00=0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll x){
if(x%4==0)return x;
else if(x%4==1)return 1;
else if(x%4==3)return 0;
else return x+1;
}
void sol(){
ll l,r;cin>>l>>r;
cout<<(f(l-1)^f(r))<<endl;
}
int main(){
int t;cin>>t;
while(t--)sol();
return 0;
}
//11 =1
//12 01 10 =11 3
//123 11 11 =00 0
//1234 00 100=100 4
//12345 100 101=01 1
//123456 01 110=111 7
//1234567 111 111=000 0
//12345678 000 1000=1000 8
//123456789 1000 1001=0001 1
//45 100 101=001 1
//456 001 110=111 7
//4567 111 111=000 0
//45678 000 1000=1000 8
//456789 1000 1001=0001 1