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