#P6115. 【模板】整式递推

    ID: 5098 远端评测题 7000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学倍增O2优化矩阵加速,矩阵优化矩阵乘法快速傅里叶变换 FFT

【模板】整式递推

Description

For an infinite sequence aa, it is known that for all nmn \ge m,

k=0mankPk(n)=0\sum_{k=0}^m a_{n-k} P_k(n) = 0

where each PkP_k is a polynomial of degree at most dd.
Given the coefficients of all PkP_k, and {ai}i=0m1\{ a_i \}_{i=0}^{m-1} , find ana_n.

Since the answer may be very large, output it modulo 998244353998244353.

Input Format

The first line contains three positive integers n,m,dn, m, d.
The second line contains mm non-negative integers, representing {ai}i=0m1\{ a_i \}_{i=0}^{m-1} .
Then there are m+1m+1 lines, each containing d+1d+1 non-negative integers; line (k+3)(k+3) gives the coefficients of PkP_k from low degree to high degree.

Output Format

Output one integer in one line, representing the answer.

5 2 1
1 0
998244352 0
998244352 1
998244352 1
44
233 2 3
1 0
998244352 0 0 0
0 998244349 4 0
0 8 998244337 8
193416411
114514 7 7
1 9 8 2 6 4 7
9 1 8 2 7 6 5 3
2 8 4 6 2 9 4 5
1 9 2 6 0 8 1 7
1 9 1 9 8 1 0 7
1 1 4 5 1 4 4 4
4 4 4 4 4 4 4 4
9 9 8 2 4 4 3 5
1 9 8 6 0 6 0 4
565704112

Hint

[Explanation of Sample 1]
Here the recurrence is an(n1)(an1+an2)(mod998244353)a_n \equiv (n-1)(a_{n-1}+a_{n-2}) \pmod{998244353}. It is easy to compute that a544(mod998244353)a_5 \equiv 44 \pmod{998244353}.

[Constraints]
For 30%30\% of the testdata, 1n1061 \le n \le 10^6.
For 100%100\% of the testdata, 1m,d71 \le m, d \le 7, 1n6×1081 \le n \le 6 \times 10^8.

All inputs are no more than 6×1086 \times 10^8.
$\forall x \in [m,n] \cap \mathbb Z \text{ s.t. } P_0(x) \not \equiv 0 \pmod{998244353}$.

Welcome to join EntropyIncreaser\mathsf E \color{red}\mathsf{ntropyIncreaser}’s fan group: 747262201.

Translated by ChatGPT 5