luogu#P5175. 数列
数列
Background
Solution: https://blog.csdn.net/kkkksc03/article/details/85008130
Problem Description
Given a sequence , where and are known.
The sequence satisfies the recurrence $a_n = x \times a_{n-1} + y \times a_{n-2} \ (n \ge 3).$
Compute .
Since the answer may be very large, output it modulo .
Input Format
The first line contains an integer , the number of test cases.
The next lines each contain integers , with the meanings as described above.
Output Format
Output lines, each containing one integer, the answer for each test case.
3
5 1 1 1 1
4 3 4 3 2
461564597527246 987489553 321654648 164165256 315648984
40
4193
480929868
Hint
Sample explanation:
For the first sample, the sequence is , so the answer is .
For the second sample, the sequence is , so the answer is .
The third sample will not be explained.
For the first of the testdata, it is guaranteed that .
For of the testdata, , , .
Translated by ChatGPT 5