题面

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. day 7-4 互斥锁与队列

    一. 基本定义 互斥锁(英语:英语:Mutual exclusion,缩写 Mutex)是一种用于多线程编程中,防止两条线程同时对同一公共资源(比如全局变量)进行读写的机制.该目的通过将代码切片成一个 ...

  2. php变量详解

    变量是用于存储信息的"容器". 定义一个变量的语法: $变量名 = 值; 使用变量的例子: <?php $x=5; $y=6; $z=$x+$y; echo $z; ?> ...

  3. C# Note33: 总结C# 6.0/7.0 新特性

    先注明,本文主体参考自:C# 6.0新特性 目前代码中使用了很多C#6.0的新特性,下面以Point类来做相关叙述: public class Point { public int X { get; ...

  4. python之路--基础数据类型的补充与深浅copy

    一 . join的用法 lst =['吴彦祖','谢霆锋','刘德华'] s = '_'.join(lst) print(s) # 吴彦祖_谢霆锋_刘德华 # join() "*" ...

  5. SQL Server中的完全连接(full join)

    一.建库和建表 create database scort use scort create table emp ( empno int primary key, ename ), sal int, ...

  6. pooling的几种形式(转)

    转载地址:http://blog.csdn.net/malefactor/article/details/51078135    原作者:张俊林 CNN是目前自然语言处理中和RNN并驾齐驱的两种最常见 ...

  7. python 计算机基础

    1.什么是编程语言. 语言是一个事物与另一个事物沟通的介质. 编程语言是程序员与计算机沟通的介质. 2.什么是编程. 编程是人按照某种语法规范设计出计算机能够识别的语言 表达的结果是程序,程序就是一系 ...

  8. HttpRequest,WebRequest,HttpWebRequest,WebClient,HttpClient 之间的区别

    HttpRequest,WebRequest,HttpWebRequest,WebClient,HttpClient 今天我们来聊一下他们之间的关系与区别. HttpRequest 类 .NET Fr ...

  9. codeforces616B

    Dinner with Emma CodeForces - 616B Jack decides to invite Emma out for a dinner. Jack is a modest st ...

  10. windows 动态库的封装以及调用

    1.一个程序从源文件编译生成可执行文件的步骤:预编译 -->  编译 -->  汇编 --> 链接(1)预编译,即预处理,主要处理在源代码文件中以“#”开始的预编译指令,如宏展开.处 ...