题目大意

求$\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. [LeetCode] 834. Sum of Distances in Tree

    LeetCode刷题记录 传送门 Description An undirected, connected treewith N nodes labelled 0...N-1 and N-1 edge ...

  2. mysql 多表查询 以及 concat 、concat_ws和 group_concat

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) 只返 ...

  3. Spring事务管理之几种方式实现事务(转)

    一:事务认识 大家所了解的事务Transaction,它是一些列严密操作动作,要么都操作完成,要么都回滚撤销.Spring事务管理基于底层数据库本身的事务处理机制.数据库事务的基础,是掌握Spring ...

  4. 说说 HTTP 和 HTTPS 区别??

    HTTP 协议传输的数据都是未加密的,也就是明文的,因此使用 HTTP 协议传输隐私信息非常不安全,为了保证这些隐私数据能加密传输,于是网景公司设计了 SSL(Secure Sockets Layer ...

  5. 第一个javascript脚本

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. win10专业版Hyper-v下Docker挂载volume的方式使用Gitlab(汉化版)保存资料数据(使用外部redis)

    目录 话题 (191) 笔记 (137) 资料区 (2) 评价 (33) 介绍 讨论区 话题 win10专业版Hyper-v下Docker挂载volume的方式使用Gitlab(汉化版)保存资料数据( ...

  7. 本地文件夹上传到Github(一)

    1.在要上传的文件夹下单击右键,选择Git Bash here打开Git bash,设置全局用户名和邮箱 语法:git config --global user.name wandou 语法:git ...

  8. left join on and和left join on where条件的困惑[转]

    外连接:left join(左联接) left outer join 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) right outer join返回包括右表中的 ...

  9. zip loader

    GS.ZipAssetLoader = function(audioContext) { this.audioContext = audioContext, this.objLoader = new ...

  10. STM32之模拟串口设计

    一.设计用途: 公司PCB制成板降成本,选择的MCU比项目需求少一个串口,为满足制成板成本和项目对串口需求,选择模拟一路串口. 二.硬件电路: 三.设计实现: 工具&软件:STM32F030R ...