// Luogu P4781 拉格朗日插值
#include <bits/stdc++.h>
#define ll long long
#define N 2003
#define MOD 998244353ll
using namespace std;
int n;
ll k, x[N], y[N];
ll ans = 0ll;
ll qpow(ll a, ll b, ll p = MOD) {
ll res = 1;
a %= p;
for (; b; b >>= 1, a = a * a % p) {
if (b & 1) {
res = res * a % p;
}
}
return (res + p) % p;
}
ll inv(ll a, ll p = MOD) { return qpow(a, p - 2); }
int main() {
scanf("%d%lld", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%lld%lld", &x[i], &y[i]);
}
for (int i = 1; i <= n; ++i) {
ll s1 = y[i];
ll s2 = 1ll;
for (int j = 1; j <= n; ++j) {
if (i == j) continue;
s1 = s1 * (k - x[j]) % MOD;
s2 = s2 * (x[i] - x[j]) % MOD;
}
ans += s1 * inv(s2) % MOD;
}
printf("%lld\n", (ans % MOD + MOD) % MOD);
return 0;
}
【多项式】拉格朗日插值
最新推荐文章于 2022-08-01 21:39:06 发布