The Sum of the k-th Powers There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).…
题目:http://codeforces.com/contest/622/problem/F 设 f(x) = 1^k + 2^k + ... + n^k 则 f(x) - f(x-1) = x^k 因为差值是 k 次的,所以 f 的次数应该是 k+1: 算出 k+2 个值就可以用拉格朗日插值求解了: 但是 k^2 会 T: #include<iostream> #include<cstdio> #include<cstring> #include<algorit…
题目:http://codeforces.com/problemset/problem/622/F 发现 sigma(i=1~n) i 是一个二次的多项式( (1+n)*n/2 ),sigma(i=1~n) i^2 是一个三次的多项式,所以 sigma(i=1~n) i^k 是一个k+1次的多项式.用拉格朗日插值就能做了. 注意别弄成 n^2 的.其实就是移动一个位置的时候乘一个数除以一个数,这样的. #include<iostream> #include<cstdio> #inc…
CF622F The Sum of the k-th Powers 题意:给\(n\)和\(k\),让你求\(\sum\limits_{i = 1} ^ n i^k \ mod \ 10^9 + 7\).\((1 \le n \le 10^9,0 \le k \le 10^6)\) 好,我们先不看题,来补一些数学. 考虑这样一个序列 \[ h_0,h_1,\dots,h_n,\dots \] 我们定义它的一个差分序列(一阶) \[ \Delta h_0, \Delta h_1, \dots ,…
题面 TJOI2018出CF原题弱化版是不是有点太过分了?对,就是 TJOI2018 教科书般的亵渎 然而我这个问题只会那个题的范围的m^3做法 回忆一下1到n求和是二次的,平方求和公式是三次的,立方求和公式是四次的,那m次方求和公式一定是个m+1次多项式 直接扔m+2个值进去把它插出来,因为是连续的可以做到线性(不算逆元) #include<cstdio> ,mod=1e9+; int n,k,ans,sum,fac[N],pre[N],suf[N]; int Qpow(int x,int…
题意 求\(\sum_{i=1}^n i^k\),\(n \leq 10^9,k \leq 10^6\) 题解 观察可得答案是一个\(k+1\)次多项式,我们找\(k+2\)个值带进去然后拉格朗日插值 \(n+1\)组点值\((x_i,y_i)\),得到\(n\)次多项式\(f\)的拉格朗日插值方法: \[f(x) = \sum_{i = 0}^n y_i\prod_{j\not =i} \frac{x-x_j}{x_i-x_j}\] 时间复杂度为\(O(n^2)\). 现在考虑这题,我们把\(…
题目描述: The Sum of the k-th Powers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find th…
F. The Sum of the k-th Powers 题目连接: http://www.codeforces.com/contest/622/problem/F Description There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109 + 7 (so you shoul…
Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there is no non-empty subarray with sum at least K, return -1. Example 1: Input: A = [1], K = 1 Output: 1 Example 2: Input: A = [1,2], K = 4 Output: -1 Exa…
Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there is no non-empty subarray with sum at least K, return -1. Example 1: Input: A = [1], K = 1 Output: 1 Example 2: Input: A = [1,2], K = 4 Output: -1 Exa…