Treasure XOR

0

0 votes
Easy-Medium
Problem

An array, A, is defined as follows:

  • A[0]=0
  • A[x]=A[x-1] ⨁x for x>0, where ⨁ refers to XOR.

You must answer Q questions. Each ith question, is in the form L[i] R[i] , and the answer is A[Li] ⨁ A[Li+1] ⨁ … ⨁ A[Ri-1] ⨁ A[Ri] (the Xor-Sum of segment [Li ,Ri] ). Print the answer to each question.

Input Format

The first line contains Q (the number of questions). The Q subsequent lines each contain two space separated integers,L and R, respectively. Line contains Li and Ri .

Constraints

1<=Q<=10^5
1<=Li<=Ri<=10^15

Output Format

On a new line for each test case i , print the exclusive-or of A's elements in the inclusive range between indices Li and Ri

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The beginning of our array looks like this: A=[0,1,3,0,4,1,7,0,8,1,11,...]

Test case 0:

3 ⨁ 0 ⨁ 4=7

Test case 1:

3 ⨁ 0 ⨁ 4 ⨁ 1 ⨁ 7 ⨁ 8=9

Test Case 2:

1 ⨁ 7 ⨁ 0 ⨁ 8 ⨁ 1 =15

Editor Image

?