解题:CF622F The Sum of the k-th Powers
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的更多相关文章
- 【LeetCode】1099. Two Sum Less Than K 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力求解 日期 题目地址:https://leetco ...
- 【LeetCode】862. Shortest Subarray with Sum at Least K 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 队列 日期 题目地址:https://leetcod ...
- [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 ...
- [题解] 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\ ...
- [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 ...
- 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 ...
- leetcode 862 shorest subarray with sum at least K
https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/ 首先回顾一下求max子数组的值的方法是:记录一个前缀min值, ...
- 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 ...
- [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 ...
随机推荐
- Laravel 5.2+ 使用url()全局函数返回前一个页面的地址
注意:文章标题中5.2+表示该文章内容可向上兼容,适用于Laravel版本5.2及更高(目前最新为5.6),但不可向下兼容,即不适用于5.2版本以下.推荐大家花一点点时间,将自己的Laravel更新至 ...
- Docker部署运行springboot项目,并使用Dockerfile制作镜像
前言: 本来是要搭建一个自动化部署分布式项目的服务器平台的,使用jenkins+k8s+ELK+springboot把一个简单的springboot项目给搞起来,由于工程太大,先分开把每个技术组件单独 ...
- K3BOM跳层
A自制件,B自制件,C外购件 ,结构为A-B-C 如果需要跳层,则设置A-B跳层,B-C跳层,则生成A计划订单,C计划订单, 假设单独A-B跳层,则MRP运算出的结果也是A计划订单,B计划订单,C计划 ...
- Delphi数据集与记录
1.1Delphi数据库应用程序的层次结构 Delphi数据库应用程序通过数据存取构件对数据库进行访问,通过可视的数据构件(Data Control)将数据呈现给用户,并与用户进行交互.Delphi数 ...
- 猜数字游戏 在控制台运行--java详解!了;来玩
import java.util.Scanner;//导入包 import java.util.Scanner; 注意格式 符号的使用 public class Demo{ //猜数字游戏 练习 pu ...
- 虚拟机linux系统明明已经安装了ubuntu,但是每次重新进入就又是选择安装界面
本文转载:https://blog.csdn.net/weixin_41522164/article/details/82814375
- LodopFuncs.js和CLodopFuncs.js区别和联系
所在位置:LodopFuncs.js可以在官网下载中心综合版里下载到.CLodopfuncs.js在C-Lodop服务缓存中,C-Lodop启动的时候才能访问到. 需不需要下载放置到项目里:(客户端本 ...
- SpringMvc父子容器
使用监听器listener来加载spring的配置文件:如下 <context-param> <param-name>contextConfigLocation</p ...
- Git简介及安装
1 Git简介 Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码 ...
- nginx-添加禁止访问规则
location ~* /application/(admin|index)/static/.*$ { allow all; } location ~* /(applicaion|addos|coe| ...