luogu#P4781. 【模板】拉格朗日插值

【模板】拉格朗日插值

Background

This is a template problem.

Problem Description

For nn points (xi,yi)(x_i, y_i), if ij,xixj\forall i \neq j, x_i \neq x_j, then these nn points uniquely determine a polynomial y=f(x)y = f(x) of degree n1n - 1.

Now, given such nn points, please determine this degree n1n - 1 polynomial and compute the value of f(k)mod998244353f(k) \bmod 998244353.

Input Format

The first line contains two integers n,kn, k.

The next nn lines each contain two integers xi,yix_i, y_i on the ii-th line.

Output Format

Output one integer in one line, representing the value of f(k)mod998244353f(k) \bmod 998244353.

3 100
1 4
2 9
3 16
10201
3 100
1 1
2 2
3 3
100

Hint

In Sample 1, the polynomial is f(x)=x2+2x+1f(x) = x^2 + 2x + 1, and f(100)=10201f(100) = 10201.

In Sample 2, the polynomial is f(x)=xf(x) = x, and f(100)=100f(100) = 100.


Constraints: 1n2×1031 \le n \le 2 \times 10^3, 1xi,yi,k<9982443531 \le x_i, y_i, k < 998244353, and all xix_i are pairwise distinct.

Translated by ChatGPT 5