解题: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 ...
随机推荐
- Baby-Step-Giant-Step 很酷的算法
Baby-Step-Giant-Step BSGS算法用于解决形如: A ^ x ≡ B ( mod C ) 的问题. 学这个算法前需要具备以下知识:快速幂取模.扩展欧几里 ...
- ubuntu 完全卸载mysql
卸载 sudo apt-get --purge remove mysql-common -y sudo apt-get --purge remove mysql* -y sudo apt-get au ...
- thinkphp5 实现搜索分页能下一页保留搜索条件
正常情况下: 搜索后分页了,点击第二页,进入页面之前的搜索条件没有了. 如代码 $keywords=$this->request->param('keywords'); $this-> ...
- Python——SMTP发送邮件
一.定义 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.python的smtplib ...
- react为按钮绑定点击事件和修改属性值
注意点:1.事件名称由react提供,所以事件名首字母大写.比如onClick,onMouseOver. 2.为事件提供的处理函数,格式必须是onClick={function},没有小括号. 3.绑 ...
- Html5 拖拽api
拖拽要有两个元素,一个是要拖动的元素,一个是要放置到的元素. 1, 在默认情况下, 只有图片和文字是可以拖拽的,其它元素都不可以.因此要想使一个元素可拖动,必须设置它的draggable 属性为tru ...
- 实现中英文混合string的逆向输出
#include <iostream> using namespace std; // 输入一个字符串(包括英文和中文),将其反序输出, 如: // hello 今天真热 ---> ...
- 解决Error:com.intellij.util.indexing.StorageException
删除 C:\Users\Nihaorz\.IntelliJIdea2017.1\system\compile-server 目录下的所有内容即可
- Go中的Init函数
init函数会在main函数执行之前进行执行.init用在设置包.初始化变量或者其他要在程序运行前优先完成的引导工作. 举例:在进行数据库注册驱动的时候. 这里有init函数 package post ...
- [BZOJ 2186] [SDOI 2008] 沙拉公主的困惑
Description 大富翁国因为通货膨胀,以及假钞泛滥,政府决定推出一项新的政策:现有钞票编号范围为 \(1\) 到 \(N\) 的阶乘,但是,政府只发行编号与 \(M!\) 互质的钞票.房地产第 ...