#P9510. 『STA - R3』高维立方体
『STA - R3』高维立方体
Problem Description
The Fibonacci sequence is defined as follows:
$$\operatorname{fib}(n)=\begin{cases}1&n\le 2\\\operatorname{fib}(n-1)+\operatorname{fib}(n-2)&n>2\end{cases}$$Now we define a function (note that when , the value of this function is ):
Since computing the prefix sum of the Fibonacci sequence is too easy, you need to compute:
$$\sum_{i=1}^n\operatorname{fib}(i)\cdot(f(i-2)+\operatorname{fib}^2(i)+\operatorname{fib}(i))$$The answer should be taken modulo the given .
Note: means the square of .
Input Format
This problem contains multiple test cases.
The first line contains an integer , the number of test cases.
For each test case, a line contains two integers .
Output Format
For each test case, output one integer per line, the result modulo .
3
2 100
3 100
4 100
4
18
60
Hint
Sample explanation:
For the first test case, .
For the second test case, $1\times(0+1^2+1)+1\times(0+1^2+1)+2\times(1+2^2+2)=18$.
Constraints
This problem uses bundled tests.
- Subtask 1 (5 points): , .
- Subtask 2 (20 points): , , .
- Subtask 3 (5 points): .
- Subtask 4 (15 points): .
- Subtask 5 (30 points): , .
- Subtask 6 (25 points): no special constraints.
For all testdata, , , 。
Translated by ChatGPT 5