#P5667. Polynomial Extrapolation via Finite Differences
Polynomial Extrapolation via Finite Differences
Polynomial Extrapolation via Finite Differences
You are given the values of a polynomial \( f(x) \) of degree at most \( n \) at \( n+1 \) consecutive integer points: \( f(0), f(1), \dots, f(n) \). You are also given a positive integer \( m \). Your task is to compute and output the values \( f(m), f(m+1), \dots, f(m+n) \) modulo \( 998244353 \).
Hint: You can uniquely determine a polynomial of degree \( \le n \) by its \( n+1 \) values. A method based on finite differences (Newton's forward difference formula) is well‐suited for this problem. In particular, it holds that:
[ f(x) = \sum_{k=0}^{n} \binom{x}{k} \Delta^k f(0)\mod 998244353, ]
where \( \Delta^k f(0) \) is the \( k \)-th finite difference computed from the given sequence, and the generalized binomial coefficient is defined as
[ \binom{x}{k} = \frac{x(x-1)\cdots(x-k+1)}{k!}. ]
inputFormat
The input consists of three lines:
- The first line contains a single integer \( n \) (\( 0 \leq n \leq \text{small}\)), representing that the polynomial has degree at most \( n \) and that \( n+1 \) values are given.
- The second line contains \( n+1 \) space-separated integers: \( f(0), f(1), \dots, f(n) \).
- The third line contains a single positive integer \( m \).
outputFormat
Output a single line with \( n+1 \) space-separated integers: \( f(m), f(m+1), \dots, f(m+n) \) (each computed modulo \( 998244353 \)).
sample
2
1 3 9
3
19 33 51