#P10007. Prefix Sum Transformation
Prefix Sum Transformation
Prefix Sum Transformation
In this problem, you are given an integer n, an integer a, and an array f
of size n+1
(with indices from 0 to n). Initially, the array f
represents the coefficients of a polynomial
You perform the following transformation exactly n times:
$$\text{For } t=1,2,\dots,n:\quad \forall\, 1\le i\le n,\quad f_i \leftarrow f_i + a\,f_{i-1}. $$After the t-th transformation, the answer ans[t]
is defined as the updated value of f[t]
. It can be shown that after t transformations the new polynomial is
Thus, we have
$$\displaystyle \text{ans}_t = \sum_{j=0}^{t}\binom{t}{j} a^{j}\,f_{t-j} \quad\text{for}\; t=1,2,\dots,n. $$Since the numbers can be very large, output each anst modulo 998244353.
inputFormat
The first line contains two integers n
and a
.
The second line contains n+1
integers: f[0], f[1], \dots, f[n]
.
outputFormat
Output n
integers: ans[1], ans[2], \dots, ans[n]
where each number is taken modulo 998244353.
sample
3 2
1 2 3 4
4 15 54