CF322F
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的更多相关文章
- 在$CF$水题の记录
CF1158C CF1163E update after CF1173 很好,我!expert!掉rating了!! 成为pupil指日可待== 下次要记得合理安排时间== ps.一道题都没写的\(a ...
随机推荐
- lvm 磁盘扩容
LVM磁盘管理 一.LVM简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它由Heinz Mauelshagen在Linux 2.4内核上实现.LVM将一个或多个硬盘 ...
- ios开发之UIView和UIViewController
UIView 表示屏幕上的一块矩形区域,负责渲染区域的内容,并且响应该区域内发生的触摸事件.它在 iOS App 中占有绝对重要的地位,因为 iOS 中几乎所有可视化控件都是 UIView 的子类. ...
- websocket(python)
1.websocket-server https://github.com/google/pywebsocket git clone https://github.com/google/pywebso ...
- Mysql语句优化建议
一.建立索引 1)考虑在 where 及 order by 涉及的列上建立索引 2)对于模糊查询, 建立全文索引 3)对于多主键查询,建立组合索引 二.避免陷阱 然而,一些情况下可能使索引无效: 1) ...
- zxing opencv
- 五、properties编写
1.properties和yml编写对比 2.properties中文乱码解决 上面的内容输出的结果 原因 idea 默认编码是UTF-8,properties需要修改对应的编码 设置编码后的结果正常 ...
- laravel5.6 基于redis,使用消息队列(邮件推送)
邮件发送如何配置参考:https://www.cnblogs.com/clubs/p/10640682.html 用到的用户表: CREATE TABLE `recruit_users` ( `id` ...
- docker 运行jenkins及vue项目与springboot项目(四.docker运行nginx)
docker 运行jenkins及vue项目与springboot项目: 一.安装docker 二.docker运行jenkins为自动打包运行做准备 三.jenkins的使用及自动打包vue项目 四 ...
- boost smart pointer
1. boost::scoped_ptr is a smart pointer that is the sole owner of a dynamically allocated object and ...
- mysql查询诊断分析工具
Query Profiler是MYSQL自带的一种query诊断分析工具,通过它可以分析出一条SQL语句的性能瓶颈在什么地方.通常我们是使用的explain,以及slow query log都无法做到 ...