题意

给出 \(n,k\) , \(n\le10^9,k\le10^6\) ,求 \(\sum_{i=1}^n i^k(mod\;10^9+7)\)

题解

自然数幂次和,是一个\(k+1\)次多项式,那么算出\(k+2\)个值然后差值就行了

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
const int N=1e6+5,P=1e9+7;
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
R int res=1;
for(;y;y>>=1,x=mul(x,x))if(y&1)res=mul(res,x);
return res;
}
int f[N],inv[N];
int n,k;
inline int Inv(R int x){return x<=k?inv[x]:ksm(x,P-2);}
int Large(int k,int n){
if(k<=n)return f[k];
int ty=(n&1)?P-1:1,tmp=1,res=0;
fp(i,1,n)tmp=1ll*tmp*(k-i)%P*Inv(i)%P;
fp(i,0,n){
res=add(res,1ll*f[i]*tmp%P*ty%P);
tmp=1ll*tmp*(k-i)%P*Inv(k-i-1)%P*(n-i)%P*Inv(i+1)%P;
ty=P-ty;
}
return res;
}
int main(){
// freopen("testdata.in","r",stdin);
scanf("%d%d",&n,&k);
inv[0]=inv[1]=1;fp(i,2,k)inv[i]=1ll*inv[P%i]*(P-P/i)%P;
fp(i,1,k+1)f[i]=add(f[i-1],ksm(i,k));
printf("%d\n",Large(n,k+1));
return 0;
}

CF622F The Sum of the k-th Powers(拉格朗日插值)的更多相关文章

  1. Educational Codeforces Round 7 F - The Sum of the k-th Powers 拉格朗日插值

    The Sum of the k-th Powers There are well-known formulas: , , . Also mathematicians found similar fo ...

  2. CF 622 F The Sum of the k-th Powers —— 拉格朗日插值

    题目:http://codeforces.com/contest/622/problem/F 设 f(x) = 1^k + 2^k + ... + n^k 则 f(x) - f(x-1) = x^k ...

  3. CF 622F The Sum of the k-th Powers——拉格朗日插值

    题目:http://codeforces.com/problemset/problem/622/F 发现 sigma(i=1~n) i 是一个二次的多项式( (1+n)*n/2 ),sigma(i=1 ...

  4. [题解] CF622F The Sum of the k-th Powers

    CF622F The Sum of the k-th Powers 题意:给\(n\)和\(k\),让你求\(\sum\limits_{i = 1} ^ n i^k \ mod \ 10^9 + 7\ ...

  5. 解题:CF622F The Sum of the k-th Powers

    题面 TJOI2018出CF原题弱化版是不是有点太过分了?对,就是 TJOI2018 教科书般的亵渎 然而我这个问题只会那个题的范围的m^3做法 回忆一下1到n求和是二次的,平方求和公式是三次的,立方 ...

  6. 「CF622F」The Sum of the k-th Powers「拉格朗日插值」

    题意 求\(\sum_{i=1}^n i^k\),\(n \leq 10^9,k \leq 10^6\) 题解 观察可得答案是一个\(k+1\)次多项式,我们找\(k+2\)个值带进去然后拉格朗日插值 ...

  7. Codeforces D. The Sum of the k-th Powers(拉格朗日插值)

    题目描述: The Sum of the k-th Powers time limit per test 2 seconds memory limit per test 256 megabytes i ...

  8. Educational Codeforces Round 7 F. The Sum of the k-th Powers 拉格朗日插值法

    F. The Sum of the k-th Powers 题目连接: http://www.codeforces.com/contest/622/problem/F Description Ther ...

  9. [Swift]LeetCode862. 和至少为 K 的最短子数组 | Shortest Subarray with Sum at Least K

    Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...

  10. LeetCode862. Shortest Subarray with Sum at Least K

    Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...

随机推荐

  1. error: reference to 'max' is ambiguous

    1.     自定义的变量名    与      库中的      重名了

  2. beans.factory.BeanCreationException beans.factory.annotation.Autowired(required=true)

    主要是这三个方面排查: 1,注入写成这样 @Autowired   private BrandServiceImpl      brandServiceImpl; 2,jar冲突,在pom.xml中 ...

  3. Linux-NoSQL之Redis(三)

    一.Redis数据常用操作 1.string常用操作 set key1  aminglinux get key1 set key1  aming //一个key对应一个value,多次赋值,会覆盖前面 ...

  4. 制作SD卡img文件,并扩容

    /********************************************************************************** * raspi-config E ...

  5. 通过rtmpdump推送海康视频流到red5服务器

    现在主流的网络摄像机都支持标准H264视频格式,例如 海康网络摄像机, 通过海康提供的网络SDK可以获取到视频码流.我测试的这款相机,视频编码采用的是H264,音频编码采用的是G711a. 这里,我仅 ...

  6. 让网站变灰的CSS代码(支持IE、FIREFOX和CHROME)(转)

    方法1:支持IE <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xht ...

  7. [转]nodejs中的process模块--child_process.exec

    1.process是一个全局进程,你可以直接通过process变量直接访问它. process实现了EventEmitter接口,exit方法会在当进程退出的时候执行.因为进程退出之后将不再执行事件循 ...

  8. NB-IoT知识

    通常,我们把物联网设备分为三类: ①无需移动性,大数据量(上行),需较宽频段,比如城市监控摄像头. ②移动性强,需执行频繁切换,小数据量,比如车队追踪管理. ③无需移动性,小数据量,对时延不敏感,比如 ...

  9. C#中打开文件、目录、保存窗口

    打开文件代码: try { OpenFileDialog of = new OpenFileDialog(); of.ShowDialog(); txt_destFilePath.Text = of. ...

  10. 用paramiko写堡垒机

    paramiko paramiko模块,基于SSH用于连接远程服务器并执行相关操作. 基本用法 SSHClient 基于用户名密码连接: 基础用法: import paramiko # 创建SSH对象 ...