题面

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. C++加载动态库的形式来实现封装

    目录结构 └── test ├── CMakeLists.txt ├── base.h //设置接口 ├── drive.cpp //具体实现 └── main.cpp //test CMakeLis ...

  2. java连接CentOS7上的redis

    这篇博客写得挺全的: https://blog.csdn.net/achenyuan/article/details/78521831?locationNum=3&fps=1 我也是跟着这篇博 ...

  3. centOS 7下无法启动网络(service network start)错误解决办法

    今天在centOS 7下更改完静态ip后发现network服务重启不了,翻遍了网络,尝试了各种方法,终于解决了. 现把各种解决方法归纳整理,希望能让后面的同学少走点歪路... 首先看问题:执行serv ...

  4. Android——线程通讯 Handler、Looper、Message;

    线程通讯问题 (主要用到了Handler类,Looper类和Message类以及MessageQueue) 在Android中主线程如何向子线程中发送消息的问题.让我们来想想,这其中的过程,无非就是创 ...

  5. Numpy中array数据操作

    1.创建: import numpy as np arr=np.array([1,2,3]) print(arr,arr.ndim) list=[1,2,3] arr=np.array(list) 2 ...

  6. nfs+keepalived高可用

    1台nfs主被服务器都下载nfs.keepalived yum install nfs-utils rpcbind keepalived -y 2台nfs服务器nfs挂载目录及配置必须相同 3.在主n ...

  7. python标准异常

    什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行.一般情况下,在Python无法正常处理程序时就会发生一个异常.异常是Python对象,表示一个错误.当Python脚 ...

  8. Yii的数值比较验证器

    该验证器比对两个特定输入值之间的关系 是否与 operator 属性所指定的相同. compareAttribute:用于与原属性相比对的属性名称. 当该验证器被用于验证某目标属性时, 该属性会默认为 ...

  9. git的简单使用(一些小操作,持续更新)

    第一次使用git的过程记录 参考了两个文章 菜鸟教程-git简明指南 阮一峰-常用git命令清单 git的几个工作区(此处参考了上面的两篇介绍) 简单步骤如下 git init 在当前目录建立工作区 ...

  10. java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.jav

    在整合spring和mybatis在执行数据库操作的时候报出了: java.lang.AbstractMethodError: org.mybatis.spring.transaction.Sprin ...