Under construction

Still being built. Things may change

Fiboxor

Time limit1sMemory limit1024 MB

Summary
For each query (k, l, r), find the XOR of Fibonacci numbers F(l) through F(r), taken modulo 2^k.
Level

Medium6 of 10

Topics
Math, Bit manipulation, Prefix sum
Solved
No attempts yet

Problem

Little Square and Little Triangle are fighting again on Valentine's day. The reason for this year's fight: Little Square claimed that the Fibonacci sequence is far prettier than the sequence of powers of two, which is Little Triangle's favorite.

The Fibonacci sequence starts with 0 and 1, and each later element is the sum of the two elements before it:

0,1,1,2,3,5,8,13,…0, 1, 1, 2, 3, 5, 8, 13, \dots

Little Triangle likes this sequence because the bitwise exclusive or (XOR) of any subarray is easy to compute. Little Triangle said that if Little Square answers QQ XOR subarray queries correctly, they will accept that Fibonacci is better. Because the Fibonacci numbers grow exponentially, Little Triangle agreed to accept only the value of each subarray XOR modulo 2k2^k.

Each of the QQ queries gives three integers kk, ll, rr. For each query, compute the XOR of the Fibonacci numbers with indexes in the interval [l,r][l, r] (both ends included, indexed from 00), modulo 2k2^k.

Constraints

  • 1≤Q≤1061 \le Q \le 10^6
  • 0≤l≤r≤10180 \le l \le r \le 10^{18}
  • 1≤k≤201 \le k \le 20

Hint

Let a⊕ba \oplus b denote the XOR of aa and bb.

In the first query, 0⊕1⊕1⊕2mod  22=2mod  4=20 \oplus 1 \oplus 1 \oplus 2 \mod 2^2 = 2 \mod 4 = 2.

In the second query, 3⊕5⊕8mod  24=14mod  16=143 \oplus 5 \oplus 8 \mod 2^4 = 14 \mod 16 = 14.

Examples1

  1. Example 1

    Input
    3
    2 0 3
    4 4 6
    20 100 1000
    
    Expected output
    2
    14
    519891