622FThe Sum of the k-th Powers
题目大意
求$\sum_{i=1}^{n} i^k$
分析
我们发现这是一个$k+1$次多项式
因此我们求出前$k+2$项然后插值即可
由于$x_i = i$
因此公式里面的乘机可以通过预处理然后循环中乘逆元的方式快速得到
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+;
const int mod = 1e9+;
int n,k,p[],inv[],sum[],Ans;
inline int pw(int x,int tot){
int res=;
while(tot){
if(tot&)res=1ll*res*x%mod;
x=1ll*x*x%mod;
tot>>=;
}
return res;
}
int main(){
int i,j,t=;
scanf("%d%d",&n,&k);
p[]=;
for(i=;i<=N;i++)p[i]=1ll*p[i-]*i%mod;
inv[N]=pw(p[N],mod-);
for(i=N-;i>=;i--)inv[i]=1ll*inv[i+]*(i+)%mod;
for(i=;i<=k+;i++)sum[i]=(sum[i-]+pw(i,k))%mod;
if(n<=k+){printf("%d\n",sum[n]);return ;}
for(i=;i<=k+;i++)t=1ll*t*(n-i)%mod;
for(i=;i<=k+;i++){
int res=1ll*sum[i]*t%mod*pw(n-i,mod-)%mod*inv[k+-i]%mod*inv[i-]%mod;
if((k+-i)&)res=mod-res;
Ans=(Ans+res)%mod;
}
printf("%d\n",Ans);
return ;
}
622FThe Sum of the k-th Powers的更多相关文章
- [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 ...
- 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 ...
- leetcode 862 shorest subarray with sum at least K
https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/ 首先回顾一下求max子数组的值的方法是:记录一个前缀min值, ...
- 862. 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 ...
- [LeetCode] 862. Shortest Subarray with Sum at Least K 和至少为K的最短子数组
Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...
- 【LeetCode】1099. Two Sum Less Than K 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力求解 日期 题目地址:https://leetco ...
- 【LeetCode】862. Shortest Subarray with Sum at Least K 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 队列 日期 题目地址:https://leetcod ...
- [LeetCode] Partition to K Equal Sum Subsets 分割K个等和的子集
Given an array of integers nums and a positive integer k, find whether it's possible to divide this ...
- hdu6058 Kanade's sum 区间第k大
/** 题目:Kanade's sum 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6058 题意:给定[1,n]的排列,定义f(l,r,k)表示区间[l ...
随机推荐
- pycharm中的Terminal 中无法使用git的问题
1.先找到git的安装路径,建议使用Everything工具 2.打开pycharm中的setting > tools > Terminal 3.把git的安装路径加上启动文件 bash. ...
- CentOS 下 redis 安装与配置
CentOS 下 redis 安装与配置 1.到官网上找到合适版本下载解压安装 [root@java src]# wget -c http://redis.googlecode.com/files ...
- Nodejs中request出现ESOCKETTIMEDOUT解决方案
做需求的时候,使用Nodejs的request批量请求某一个接口,由于接口超时,出现 ESOCKETTIMEDOUT,程序中断 为了让程序遇到 ESOCKETTIMEDOUT 之后能够继续执行下去,需 ...
- Eureka注册中心高可用及常用配置项
一.前言 前面已经简单的介绍了 Eureka 注册中心的使用以及查看.下面将继续进行 Eureka 的说明以及应用. 二.Eureka 的高可用搭建 在实际生产项目中,为了保证服务的可用性,连续性,一 ...
- ASP.NET @URL帮助类
原文: https://www.cnblogs.com/bobo-show/p/5746389.html https://www.cnblogs.com/zhuji/p/7698057.html ...
- Android客户端与Python服务器端通信之上传图片
继上篇成功的与服务器端通信上之后,我现在需要将安卓本地的图片上传到服务端.服务端接收图片存下来. 参考:https://blog.csdn.net/qq_26906345/article/detail ...
- Scrapy抓取jobbole数据
1.python版本3.6.1 2.python编辑器:JetBrains PyCharm 2.安装virtualenvwrapper-win pip3 install virtualenvwrapp ...
- 修改 linux 默认字符集
[root@eric6 ~]# cat /etc/sysconfig/i18n //查看 linux 默认的字符集,默认是 UTF-8 LANG="zh_CN.UTF-8" cp ...
- nodejs 更新代码自动刷新页面
安装第三方工具: nodemon npm install --global nodemon 安装完毕后使用: 之前使用: node xxx.js 改成 nodemon xxx.js 只要通过nodem ...
- gay绿论第一章两点注意事项
1.不可能事件的概率为0,但概率为0的事件不一定是不可能事件,例如从自然数中取一个数结果是1的概率,从极限角度看,分子是1,分母是∞,结果是0,但它显然是有可能发生的,所以不是不可能事件. 2.两事件 ...