FallDream dalao找的插值练习题

题目大意:给定n,k,求Σi^k (i=1~n),对1e9+7取模。(n<=10^9,k<=10^6)

思路:令f(n)=Σi^k (i=1~n),则有f(n)-f(n-1)=n^k,说明f(n)的差分是n的k次多项式,则所求f(n)为n的k+1次多项式,利用拉格朗日插值公式,我们暴力计算n=0~k+1时的答案,代入公式,利用预处理的信息加速计算,总复杂度O(klogMOD)。

#include<cstdio>
#define MOD 1000000007
int pw(int x,int y)
{
int r=;
for(;y;y>>=,x=1LL*x*x%MOD)if(y&)r=1LL*r*x%MOD;
return r;
}
#define MK 1000000
int z[MK+];
inline int mod(int a){return a>=MOD?a-MOD:a;}
int main()
{
int n,k,i,ans=,s0=,s1=;
scanf("%d%d",&n,&k);
for(i=;i++<=k;)z[i]=mod(z[i-]+pw(i,k));
if(n<=++k)return printf("%d",z[n]),;
for(i=;i<=k;++i)s0=1LL*s0*(n-i)%MOD;
for(i=;i<=k;++i)s1=1LL*s1*(MOD-i)%MOD;
for(i=;i<=k;++i)
ans=(ans+1LL*z[i]*s0%MOD*pw(n-i,MOD-)%MOD*pw(s1,MOD-))%MOD,
s1=1LL*s1*pw(MOD-k+i,MOD-)%MOD*(i+)%MOD;
printf("%d",ans);
}

附:

拉格朗日插值公式:

牛顿插值公式:

[Educational Codeforces Round 7]F. The Sum of the k-th Powers的更多相关文章

  1. 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 ...

  2. 【Educational Codeforces Round 37 F】SUM and REPLACE

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...

  3. 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 ...

  4. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  5. Educational Codeforces Round 53 E. Segment Sum(数位DP)

    Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...

  6. Educational Codeforces Round 26 F. Prefix Sums 二分,组合数

    题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/72 ...

  7. Educational Codeforces Round 14 - F (codeforces 691F)

    题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围: ...

  8. Educational Codeforces Round 1 A. Tricky Sum 暴力

    A. Tricky Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem ...

  9. Educational Codeforces Round 23 F. MEX Queries 离散化+线段树

    F. MEX Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. bzoj千题计划108:bzoj1018: [SHOI2008]堵塞的交通traffic

    http://www.lydsy.com/JudgeOnline/problem.php?id=1018 关键点在于只有两行 所以一个2*m矩形连通情况只有6种 编号即对应代码中的a数组 线段树维护 ...

  2. 06-移动端开发教程-fullpage框架

    CSS3的新特性已经讲完了,接下来我们看一下jQuery的一个全屏jQuery全屏滚动插件fullPage.js.我们经常见到一些全屏的特绚丽页面,手指或者鼠标滑动一下就是一整屏切换,而且还有各种效果 ...

  3. Linux "零拷贝" sendfile函数中文说明及实际操作

    Sendfile函数说明 #include ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count); sendfile ...

  4. js 防止重复点击

    1.添加flag 适用于ajax 表单提交,提交之前flag = false , 提及中,true ,提交后false 2.事件重复点击: <script> var throttle = ...

  5. kubernetes入门(09)kubernetes1.7集群安装(2017/11/13)

    CentOS7.3利用kubeadm安装kubernetes1.7.3完整版(官方文档填坑篇) https://www.cnblogs.com/liangDream/p/7358847.html 一. ...

  6. 修改了SpringBoot的主类名称后,gradle build报错的解决办法

    Unable to find a single main class from the following candidates [*.*Application]

  7. UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 1987: illegal multibyte sequence

    在爬取 url = "http://stats.meizhou.gov.cn/show/index/1543/1689" 时出现了问题: UnicodeEncodeError: ' ...

  8. Codeforces Round #436 (Div. 2) B. Polycarp and Letters

    http://codeforces.com/contest/864/problem/B 题意: 给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字 ...

  9. Django:(博客系统)添加文章(中文)出现UnicodeEncodeError乱码

    添加文章时出现了一个UnicodeEncodeError乱码问题 在添加文章时,抛出了异常: 解决方案,修改manage.py(添加import sys reload(sys) sys.setdefa ...

  10. baidu地图:实现多点连线渲染

    <script type="text/javascript"> var points = [ {"Lng":125.17787645967861,& ...