Number of ways in a range
Practice
0 (0 votes)
Linear algebra
Hard
Recruit
Approved
Grammar Verified
Mathematics
Matrix exponentiation
Problem
100% Success 3 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given three integers, namely L, R, and X, where X varies from \([L, R]\).

Write a program to find the sum of the number of ways in which X people are chosen. If you choose a \(person_i\) \((1 \le i \le X)\), then you cannot choose its neighboring person.

Input format

  • First line: T (number of test cases)
  • First line in each test case: Two space-separated integers L and R

Output format

For each test case, print the sum of the number of ways modulo \(10^9 + 7\) in which X people are chosen, where if you choose a \(person_i\) \((1 \le i \le X)\), you can choose one or none of its immediate neighbors, but not both.

Constraints

\(1 ≤ T ≤ 10^3\)
\(1 ≤ L ≤ R ≤ 10^9\)

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
42 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsMathOpenSorting
Points:30
48 votes
Tags:
Ad-HocAlgorithmsApprovedHash MapsMediumOpen
Points:50
2 votes
Tags:
Linear AlgebraHardApprovedMathematicsOpenMatrix Exponentiation