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 ...
随机推荐
- 取消a或input标签聚焦后出现虚线框
1:在a标签里加入js控制,当a标签被聚焦时,强制取消焦点,这时候a标签自然不会有虚线框. <a href="#" onfocus="this.blur();&qu ...
- 关于iphone 6s 页面功能不能正常使用问题
6s 不支持es6 语法.去除es6语法后页面功能正常使用!!!!!
- [Python3] 006 列表的常用方法
目录 一个篱笆三个桩,list 有--好多个桩 1. 列表的小伙伴们 (1) 召唤小伙伴 (2) 我给"他们"分了个组 2. 小伙伴们的"才艺展示" (1) & ...
- spring-第十五篇之AOP面向切面编程之AspectJ框架简单应用
1.去官方网站下载aspectj-1.8.0.jar 2.在jar包目录启动cmd,执行java -jar aspectj-1.8.0.jar,Next 3.检查JAVA_HOME路径是否正确,如果不 ...
- HDU 1174 题解(计算几何)
题面: 爆头 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- OSI模型——传输层
OSI模型——传输层 运输层 运输层概述 运输层提供应用层端到端通信服务,通俗的讲,两个主机通讯,也就是应用层上的进程之间的通信,也就是转换为进程和进程之间的通信了,我们之前学到网络层,IP协议能将分 ...
- 搜索(DFS)---填充封闭区域
填充封闭区域 130. Surrounded Regions (Medium) For example, X X X X X O O X X X O X X O X X After running y ...
- C# 同步调用 异步调用 异步回调 多线程的作用
同步调用 : 委托的Invoke方法用来进行同步调用.同步调用也可以叫阻塞调用,它将阻塞当前线程,然后执行调用,调用完毕后再继续向下进行. 异步调用 :同步调用会阻塞线程,如果是要调用一项繁重的 ...
- Latex--入门系列一
Latex 专业的参考 tex对于论文写作或者其他的一些需要排版的写作来说,还是非常有意义的.我在网上看到这个对于Latex的入门介绍还是比较全面的,Arbitrary reference .所以将会 ...
- h5与app交互
现在移动端 web 应用,很多时候都需要与原生 app 进行交互.沟通(运行在 webview中),比如微信的 jssdk,通过 window.wx 对象调用一些原生 app 的功能.所以,这次就来捋 ...