CF322F

拉格朗日插值

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define M 1100001
#define LL long long
#define P ((LL)1e9+7)
using namespace std; int n,m,k;
LL f[M],inv[M],Inp[M],Inl[M],A=1,res; LL qick(LL x,LL y)
{
LL z=1;
for(y;y;y>>=1, x=x*x%P) if(y&1) z=z*x%P;
return z;
} int main()
{
scanf("%d%d",&n,&m);
k=m+2; for(int i=1;i<=k;i++) f[i]=(f[i-1]+qick(i,m))%P;
inv[0]=Inp[0]=inv[1]=Inp[1]=1;
for(int i=2;i<=k;i++) inv[i]=(P-P/i)*inv[P%i]%P;
for(int i=1;i<=k;i++) Inp[i]=Inp[i-1]*inv[i]%P;
for(int i=n;i>=n-k;i--) A=A*i%P;
if(k>=n) {printf("%I64d",f[n]); return 0;}
for(int i=1;i<=k;i++)
{
int w=qick(n-i,P-2);
LL Inv=(Inp[i]*Inp[k-i])%P;
if((k-i)&1) Inv*=-1;
res=(res+Inv*A%P*w%P*f[i])%P;
}
printf("%I64d",(res+P)%P);
}

CF322F的更多相关文章

  1. 在$CF$水题の记录

    CF1158C CF1163E update after CF1173 很好,我!expert!掉rating了!! 成为pupil指日可待== 下次要记得合理安排时间== ps.一道题都没写的\(a ...

随机推荐

  1. 使用vue配合组件--转载

    1.由饿了么 UED (知乎专栏)设计的桌面端组件库已经开源,文档:Element,仓库: GitHub - ElemeFE/element: Desktop UI elements for Vue. ...

  2. Comet OJ - Contest #12

    B 整个表格其实是一些联通块,取反操作不能跨连通块.所以直接统计一下每个连通块内数字不对的个数是不是偶数即可 #include<iostream> #include<cstring& ...

  3. hdu 1130How Many Trees?(卡特兰数)

    卡特兰数又称卡塔兰数,英文名Catalan number,是组合数学中一个常出现在各种计数问题中出现的数列. 以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)的名字来命名,其前几项为(从第零 ...

  4. docker--container之间的link,bridge create

    container的name和ID一样,也是唯一的,当不知道container的IP时,可以用name替代,但需要先配置link 下面创建两个container 时,未配置link所以ping nam ...

  5. struts2之ModelDriven

    在Struts 2中,提供了另外一种直接使用领域对象的方式,就是让action实现com.opensymphony. xwork2.ModelDriven接口.ModelDriven让你可以直接操作应 ...

  6. hibernate 参数一览

    实现包含了Hibernate与数据库的基本连接信息的配置方式有两种方式: 第一种是使用hibernate.properties文件作为配置文件. 第二种是使用hibernate.cfg.xml文件作为 ...

  7. 将word文档中的回车符进行删除

  8. java switch语句注意事项

    /* switch语句的使用注意事项: 1.多个case后面的数据不可以重复 2.switch后面的小括号当中只能是下列数据类型: 基本数据类型:byte . short.char.int 引用数据类 ...

  9. element el-table 合计在横拉滚动条的下面,正确展示应该是滚动条在合计下面

    <style lang="less"> .el-table{ overflow: auto; } .el-table .el-table__body-wrapper, ...

  10. sql对表的操作

    --insert into pppcopy select * from ppp //从表ppp中获取数据,并将其插入到pppcopy中,只拷贝表的数据,不拷贝表的结构(前提:表pppcopy1存在) ...