题目大意

求$\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的更多相关文章

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

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

  3. leetcode 862 shorest subarray with sum at least K

    https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/ 首先回顾一下求max子数组的值的方法是:记录一个前缀min值, ...

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

  5. [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 ...

  6. 【LeetCode】1099. Two Sum Less Than K 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力求解 日期 题目地址:https://leetco ...

  7. 【LeetCode】862. Shortest Subarray with Sum at Least K 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 队列 日期 题目地址:https://leetcod ...

  8. [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 ...

  9. hdu6058 Kanade's sum 区间第k大

    /** 题目:Kanade's sum 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6058 题意:给定[1,n]的排列,定义f(l,r,k)表示区间[l ...

随机推荐

  1. Linux下杀进程

    $ ps -ef | grep firefox smx : ? :: /usr/lib/firefox-/firefox-bin smx : pts/ :: grep --color=auto fir ...

  2. c#工厂模式

    创建一个抽象类: public abstract class Test {  public abstract void Print();//输出信息} 创建输出123的测试类 public class ...

  3. mysql部署-主从搭建

    一.安装数据库 yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release ...

  4. 一次特殊的“VARCHAR转numeric失败”错误记录

    今天接触到一个很有意思的问题.当我在执行一条INSERT的sql语句时,他总是报字符串转数字类型失败. 问题 首先,该表中的所有数字类型的字段都是非必填,其次,每个数字类型的字段都有默认值.最令我感到 ...

  5. TFS版本对应

    原文: MSDN Operating systems TFS can be installed on a Windows server or client operating system. TFS ...

  6. vs2015上编译QT程序的环境搭建

    下载相对应版本的QT(以QT5.7.0为例),进入网站http://download.qt.io/archive/qt/5.7/5.7.0/,下载MSVC版本QT,我的系统是64位,VS版本是2015 ...

  7. C++之匿名对象与析构函数的关系

    #include <iostream> using namespace std; class Location{ public: Location(, ){ X = xx; Y = yy; ...

  8. Excel VBA获取当文件下级子目录或目录中文件

    '====================================================================== '功能: 查找指定文件夹含子文件夹内所有文件名或文件夹名 ...

  9. 关于Python程序的运行方面,有什么手段能提升性能?

    1.使用多进程,充分利用机器的多核性能 2.对于性能影响较大的部分代码,可以使用C或C++编写 3.对于IO阻塞造成的性能影响,可以使用IO多路复用来解决 4.尽量使用Python的内建函数 5.尽量 ...

  10. Dynamic Mapping和常见字段类型

    原文:Dynamic Mapping和常见字段类型 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn. ...