题意

给出 \(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. Php处理大文件-分割和合并

    分割文件 /* * 分割文件 * 默认大小 2M=10485760/5 */ function file_split($file,$block_size=10485760/5) { $block_in ...

  2. C# Winform 基于Task的异步与延时执行

    一.Task的机制   Task位于命名空间System.Threading.Tasks中,是.NET 4.0加入的新模块,其实现机制大致类似于线程池ThreadPool,不过对于ThreadPool ...

  3. html5 tab横向滚动,无滚动条(transform:translate)

    html5 横向滚动,用到了 touchstart.touchmove.touchend 控制修改transform:translate属性;[手机端或者浏览器模拟手机模式才有效果] [转载请注明出处 ...

  4. leetcode 2 Add Two Numbers(链表)

    数字反过来这个没有什么麻烦,就是镜像的去算十进制加法就可以了,然后就是简单的链表. /** * Definition for singly-linked list. * struct ListNode ...

  5. Java自定义分页标签的实现

    主要字段含义: 页号 pagaNo页面大小 pageSize总记录条数 recordCount计算本次一共分多少页 myPageSize页号显示开始 start 页号显示结束 end PageTag需 ...

  6. freeMarker(十四)——XML处理指南之必要的XML处理

    学习笔记,选自freeMarker中文文档,译自 Email: ddekany at users.sourceforge.net 1.基本内容 假设程序员在数据模型中放置了一个XML文档,就是名为 d ...

  7. OSS阿里云文件上传 demo。

    所需jar包: aliyun-openservices-1.2.3.jar jdom-1.1.jar commons-codec-1.4.jar commons-logging-1.1.1.jar g ...

  8. 搞事情 -- python之线程

    简介 操作系统线程理论 线程概念的引入背景 线程的特点 进程和线程的关系 使用线程的实际场景 用户级线程和内核级线程(了解) 线程和python 理论知识 线程的创建Threading.Thread类 ...

  9. flume入门之一:flume 安装及测试

    http://flume.apache.org/ flume下载:http://mirror.bit.edu.cn/apache/flume/1.7.0/apache-flume-1.7.0-bin. ...

  10. oracle--事物---

    一.什么是事务 事务用于保证数据的一致性,它由一组相关的dml语句组成,该组的dml(数据操作语言,增删改,没有查询)语句要么全部成功,要么全部失败. 如:网上转账就是典型的要用事务来处理,用于保证数 ...