#P5808. 【模板】常系数非齐次线性递推
【模板】常系数非齐次线性递推
Description
Given the recurrence:
$$a_n = P(n) + \sum\limits_{i=1}^k f_i \times a_{n-i}$$where is a polynomial of degree .
Given , , and the coefficients of , find .
Output the answer modulo .
Input Format
The first line contains three positive integers .
The second line contains integers, representing .
The third line contains integers, representing .
The fourth line contains integers, from low degree to high degree, representing the coefficients of .
Output Format
Output one line with one integer, representing the answer.
40 5 6
1 2 3 5 8 13
1 3 4 9 6 7
1 1 4 5 1 4
349344375
Hint
Constraints
For of the testdata, , .
Except for the first line, all input numbers are in the range .
The testdata has multiple difficulty levels.
Translated by ChatGPT 5
京公网安备 11011102002149号