拉格朗日插值 模板
#include<cstdio>
#include<cstring>
using namespace std;
#define N 2010
#define md 998244353
#define ll long long
struct {
ll x, y;
}a[N];
ll ksm(ll x, ll y) {
if(!y) return 1;
ll l = ksm(x, y / 2);
if(y % 2) return l * l % md * x % md;
return l * l % md;
}
int main() {
int n, i, j;
ll k;
scanf("%d%lld", &n, &k);
for(i = 1; i <= n; i++) {
scanf("%lld%lld", &a[i].x, &a[i].y);
}
ll ans = 0;
for(i = 1; i <= n; i++) {
ll t = a[i].y, s = 1;
for(j = 1; j <= n; j++) if(j != i) {
s = s * (a[i].x - a[j].x) % md;
t = t * (k - a[j].x) % md;
}
ans = (ans + t * ksm(s, md - 2)) % md;
}
printf("%lld", (ans % md + md) % md);
return 0;
}
哈哈哈哈哈哈哈哈哈哈