Easy Homework
Time limit1.5sMemory limit256 MB
Count the indices n in [L, R] where f(n) mod p equals x, for the sequence f(0)=0, f(1)=1, f(n)=A·f(n-1)+f(n-2).
- Level
Hard8 of 10
- Topics
- Number theory, Matrix, Math
- Solved
- No attempts yet
Problem
Fix an integer . A sequence satisfies the following two conditions.
- ,
- for every integer .
Given a prime and an integer (), count the indices with that satisfy .
Input
The first line contains an integer , the number of test cases ().
Each of the next lines contains five integers , , , and (, , , ). It is guaranteed that is prime.
Output
Print lines. Line contains the answer for the -th test case.