New Sequence
Practice
0 (0 votes)
Matrix exponentiation
Hard
Approved
Recruit
Problem
18 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a sequence whose first and the second elements are 0 and 1 respectively.
The \(i^{th}\) element of sequence is given by:

\(b_i\) = \((-1)^{i+1}\) * \([ |b_{i-1}| + |b_{i-2}| ]\)

where |K| represents the absolute value of K. If the element is very large, take modulo with \(10^9+7\).
Write a program to find the sum of the sequence having indexes between L and R (L and R inclusive). If the answer is very large, output it as modulo \(10^9+7\). It is guaranteed that result will always be positive.

Input Format
First line: T, the number of test cases
Next T lines: L and R

Output Format
For each test case, output an integer which is the sum of all elements having indexes between L and R of the given sequence.

Input Constraints:
\(1 \le T \le 10^4\)
\(0 \le L \le 10^{15}\)
\(L \le R \le 10^{15}\)
0-based indexing is followed.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
35 votes
Tags:
Ad-HocApprovedBasic ProgrammingEasyOpen
Points:30
97 votes
Tags:
Dynamic ProgrammingEasyOpenRecursion
Points:50
2 votes
Tags:
GraphsDynamic ProgrammingAlgorithmsTrees