题面

TJOI2018出CF原题弱化版是不是有点太过分了?对,就是 TJOI2018 教科书般的亵渎

然而我这个问题只会那个题的范围的m^3做法

回忆一下1到n求和是二次的,平方求和公式是三次的,立方求和公式是四次的,那m次方求和公式一定是个m+1次多项式

直接扔m+2个值进去把它插出来,因为是连续的可以做到线性(不算逆元)

 #include<cstdio>
const int N=1e6+,mod=1e9+;
int n,k,ans,sum,fac[N],pre[N],suf[N];
int Qpow(int x,int k)
{
if(k<=) return k?x:;
int tmp=Qpow(x,k>>);
return 1ll*tmp*tmp%mod*((k&)?x:)%mod;
}
int main()
{
scanf("%d%d",&n,&k);
fac[]=pre[]=suf[k+]=;
for(int i=;i<=k+;i++) fac[i]=1ll*fac[i-]*i%mod;
for(int i=;i<=k+;i++) pre[i]=1ll*pre[i-]*(n-i+mod)%mod;
for(int i=k+;i;i--) suf[i]=1ll*suf[i+]*(n-i+mod)%mod;
for(int i=;i<=k+;i++)
{
sum=(sum+Qpow(i,k))%mod;
int fz=1ll*pre[i-]*suf[i+]%mod;
int fm=1ll*fac[i-]*fac[k+-i]%mod;
(ans+=1ll*sum*fz%mod*Qpow(((k-i)&)?mod-fm:fm,mod-)%mod)%=mod;
}
printf("%d",ans);
return ;
}

解题:CF622F The Sum of the k-th Powers的更多相关文章

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

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

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

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

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

  4. [题解] CF622F The Sum of the k-th Powers

    CF622F The Sum of the k-th Powers 题意:给\(n\)和\(k\),让你求\(\sum\limits_{i = 1} ^ n i^k \ mod \ 10^9 + 7\ ...

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

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

  7. leetcode 862 shorest subarray with sum at least K

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

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

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

随机推荐

  1. [转帖]你云我云•兄弟夜谈会 第三季 企业IT架构

    你云我云•兄弟夜谈会 第三季 企业IT架构 https://www.cnblogs.com/sammyliu/p/10425252.html 你云我云•兄弟夜谈会 第三季 企业IT架构 你云我云•兄弟 ...

  2. java随笔4 java中接参整形转字符串

    通过+‘’来实现

  3. Day 4-2 random模块

    import random random.randint(1,100) # 从1到100中随机取出一个数.包含100 random.randrange(1,100) #功能和上面一样.只是不包含100 ...

  4. .Net MVC4 log4net的配置

    一.首先在使用log4net记录日志的时候,我们要引用log4net.dll文件 二.在web.config中添加一下配置代码 <configSections> <!-- For m ...

  5. restful 规范(建议)

    需求:开发cmdb,对用户进行管理. 做前后端分离,后端写api(URL),对用户表进行增删改查,应该写四个URL(还要给文档(返回值,返回,请求成功,干嘛,失败,干嘛)),然后分别写视图函数. ht ...

  6. mysql 数据库的主从同步

    1.复制准备 操作系统 centOS 主库(mysql master):  ip为123.56.94.1   port为3306  mysql 版本 5.7.16 从库(mysql slave):   ...

  7. vue計算屬性

    計算屬性:computed 和method的差別:computed是基於它的依賴緩存,只有它的相關依賴發生改變時才會重新獲取值. method是在重新渲染時,函數總會重新調用. comuputed:默 ...

  8. Stream、FileStream、MemoryStream的区别

    1.Stream:流,在msdn的定义:提供字节序列的一般性视图,Stream提供了读写流的方法是以字节的形式从流中读取内容.而我们经常会用到从字节流中读取文本或者写入文本,微软提供了StreamRe ...

  9. 目前市场上有些什么样的数据库管理系统(DBMS),它们都有什么特点?它们之间的优缺点有什么?它们的使用场合分别是?

    1 要求 目前市场上有些什么样的数据库管理系统(DBMS),它们都有什么特点?它们之间的优缺点有什么?它们的使用场合分别是? 1.1 目前市场上有些什么样的数据库管理系统(DBMS) 目前市场上的数据 ...

  10. HTML5-Input

    HTML5拥有多个新的表单输入类型,这些新特性提供了更好的输入控制和验证(有的浏览器不支持) color.date.datetime.datetime-local.email.month.number ...