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);
}

最新文章

  1. jdk源码分析红黑树——插入篇
  2. [DPDK][转]DPDK编程开发(4)—lcore
  3. 浅谈数位DP
  4. AOP理解
  5. 在vs2013中配置openGL(绝对可靠 !)
  6. 批处理bat命令--获取当前盘符和当前目录和上级目录
  7. hdu 5432 Pyramid Split(二分搜索)
  8. [译]Stairway to Integration Services Level 13 - SSIS 变量回顾
  9. 另存了一次网页之后其它word打开格式都变了
  10. MySQL Hardware--网络测试
  11. N个工作日后的日期
  12. Python TypeError: &#39;module&#39; object is not callable 原因分析
  13. Hystrix 详细说明
  14. mybatis学习五 log4j
  15. Python 入门基础11 --函数基础4 迭代器、生成器、枚举类型
  16. 题解 P1894 【[USACO4.2]完美的牛栏The Perfect Stall】
  17. 数组中的each 和 jquery 中的 each
  18. API(选项/数据 选项/dom)
  19. 怎么在windows10中关闭Windows Defender?
  20. oracle密码过期解决方法

热门文章

  1. Scrapy框架: 异常错误处理
  2. linux mysql数据库安装
  3. c# 编程--结构体
  4. OpenCV/Python/dlib眨眼检测
  5. 基于 Scrapy-redis 两种形式的分布式爬虫
  6. 在脚本中使用set命令调试脚本
  7. 四、yml文件的写法
  8. web之请求转发与重定向
  9. 工具类Collections、Arrays(传入的是数组)
  10. 常见算法和数据结构存在的坑(updating)