题目大意

求$\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. Creat-React-Native-App 之StackNavigator之踩坑记录

    Creat-React-Native-App简称CRNA. 在我开始入门RN时fb已经推出和Expo联合开发用于快速创建React Native应用的工具: Create-React-Native-A ...

  2. 000 (H5*) 知识点总结

    https://note.youdao.com/ynoteshare1/index.html?id=ff02e616917fba868f39241c8383d7c7&type=note 目录 ...

  3. [BZOJ 3731] Gty的超级妹子树 (树分块)

    [BZOJ 3731] Gty的超级妹子树 (树分块) 题面 给出一棵树(或森林),每个点都有一个值.现在有四种操作 1.查询x子树里>y的值有多少个 2.把点x的值改成y 3.添加一个新节点, ...

  4. 简单易用的leetcode开发测试工具(npm)

    描述 最近在用es6解leetcode,当问题比较复杂时,有可能修正了新的错误,却影响了前面的流程.要用通用的测试工具,却又有杀鸡用牛刀的感觉,所以就写了个简单易用的leetcode开发测试工具,分享 ...

  5. body传参?parameter传参?Request Payload?Query String Parameter?

    今天,是有委屈的一天:今天,是有小情绪的一天.所以,我们要对今天进行小结,跟它做一个了断! 今天,后端来一个接口,告诉我"要用post请求,parameter形式传参".over. ...

  6. Log4Net 之走进Log4Net (四)

    原文:Log4Net 之走进Log4Net (四) 一.Log4net的结构 log4net 有四种主要的组件,分别是Logger(记录器), Repository(库), Appender(附着器) ...

  7. moongoose对象无法新增删除属性

    昨天用nodes中的moongoose去查询一个结果遇到一个大坑,这个坑貌似用moongoose可能会遇到.背景是这样的,我在nodejs中去查询document,得到的可以看作是一个对象list.在 ...

  8. 封装和private,this,super关键字的简单应用

    1.将成员变量用private修饰 2.提供对应的getxx()和setxx()方法 public class Student { private String name; private int a ...

  9. Sql中使用Case when

    SELECT CASE WHEN Column IS NOT NULL THEN '情况1' ELSE '情况2' END AS '列名' , FROM dbo.Table

  10. 安装FaaS

    [root@localhost ~]# [root@localhost ~]# new OS:centos-7 [root@localhost ~]# [root@localhost ~]# vim ...