Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

How to find XOR of all the elements in given range?

$
0
0
#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;
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>