# 什么是拉格朗日插值

$f(x)=\sum_{i=1}^{n+1}y_i\prod_{j\neq&space;i}\frac{(x-x_j)}{(x_i-x_j)}$

# 推荐博客

Ebola的OI笔记：拉格朗日插值 学习笔记

# 板子题

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

### 说明

n \leq 2000 \; \; \; x_i,y_i,k \leq 998244353

### 题目分析

 1 #include<bits/stdc++.h>
2 const int maxn = 2035;
3 const int MO = 998244353;
4
5 int x[maxn],y[maxn],n,k,ans;
6
7 int qmi(int a, int b)
8 {
9     int ret = 1;
10     while (b)
11     {
12         if (b&1)
13             ret = 1ll*ret*a%MO;
14         a = 1ll*a*a%MO, b >>= 1;
15     }
16     return ret;
17 }
18 int main()
19 {
20     scanf("%d%d",&n,&k);
21     for (int i=1; i<=n; i++)
22         scanf("%d%d",&x[i],&y[i]);
23     for (int i=1; i<=n; i++)
24     {
25         int upp = 1, low = 1;
26         for (int j=1; j<=n; j++)
27         {
28             if (i==j) continue;
29             upp = 1ll*upp*(k-x[j])%MO;
30             low = 1ll*low*(x[i]-x[j])%MO;
31         }
32         upp = (upp%MO+MO)%MO, low = (low%MO+MO)%MO;
33         ans = (ans+1ll*y[i]*upp%MO*qmi(low, MO-2)%MO)%MO;
34     }
35     printf("%d\n",ans);
36     return 0;
37 }

END

posted @ 2018-08-07 16:18 AntiQuality 阅读(...) 评论(...) 编辑 收藏