#P5808. 【模板】常系数非齐次线性递推

    ID: 4772 远端评测题 4000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学递推O2优化快速傅里叶变换 FFT快速数论变换 NTT

【模板】常系数非齐次线性递推

Description

Given the recurrence:

$$a_n = P(n) + \sum\limits_{i=1}^k f_i \times a_{n-i}$$

where P(x)P(x) is a polynomial of degree mm.

Given f1,f2,,fkf_1,f_2,\dots,f_k, a0,a1,,ak1a_0,a_1,\dots,a_{k-1}, and the coefficients of P(x)P(x), find ana_n.
Output the answer modulo 998244353998244353.

Input Format

The first line contains three positive integers n,m,kn,m,k.
The second line contains kk integers, representing a0,a1,,ak1a_0,a_1,\dots,a_{k-1}.
The third line contains kk integers, representing f1,f2,,fkf_1,f_2,\dots,f_k.
The fourth line contains m+1m+1 integers, from low degree to high degree, representing the coefficients of P(x)P(x).

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 100%100\% of the testdata, 1n1091\le n \le 10^9, 1m,k300001\le m,k \le 30000.
Except for the first line, all input numbers are in the range [0,998244353)[0,998244353).

The testdata has multiple difficulty levels.

Translated by ChatGPT 5