Fiboxor
Time limit1sMemory limit1024 MB
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:
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 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 .
Each of the queries gives three integers , , . For each query, compute the XOR of the Fibonacci numbers with indexes in the interval (both ends included, indexed from ), modulo .
Constraints
Hint
Let denote the XOR of and .
In the first query, .
In the second query, .