拉个狼日插值 亩版题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #define LL long long #define ULL unsigned long long #define rep(i,j,k) for(int i=j;i<=k;i++) #define dep(i,j,k) for(int i=k;i>=j;i--) #define INF 0x3f3f3f3f #define mem(i,j) memset(i,j,sizeof(i)) #define make(i,j) make_pair(i,j) #define pb push_back #define PI acos(-1.0) using namespace std; const int N = 2005, mod = 998244353; int n, x[N], y[N], k; int inv(int x, int b = mod - 2, int ans = 1) { for(; b; b >>= 1, x = 1LL * x * x % mod) if(b & 1) ans = 1LL * ans * x % mod; return ans; } int Lagrange(int n, int *x, int *y, int k) { int ans = 0; rep(i, 1, n) { int s1 = 1, s2 = 1; rep(j, 1, n) if(i != j) s1 = 1LL * s1 * (k - x[j] + mod) % mod, s2 = 1LL * s2 * (x[i] - x[j] + mod) % mod; ans = (ans + 1LL * y[i] * s1 % mod * inv(s2) % mod) % mod; } return ans; } int main() { scanf("%d %d", &n, &k); rep(i, 1, n) scanf("%d %d", &x[i], &y[i]); return printf("%d\n", Lagrange(n, x, y, k)), 0; }
一步一步,永不停息