题目: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…
\(>Codeforces \space 622\ F. The\ Sum\ of\ the\ k-th\ Powers<\) 题目大意 : 给出 \(n, k\),求 \(\sum_{i=1}^{n} i^k\) 对 \(10^9 +7\) 取模的值 \(1 \leq n \leq 10^9, 0 \leq k \leq 10^6\) 解题思路 : 考虑 \(k\) 比较大,且模数不太好 \(NTT\),于是考虑插值做法, 学习了一波插值之后,发现就是个板子题 (雾) 拉格朗日插值: 对于…
题目: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…
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).…
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…
FallDream dalao找的插值练习题 题目大意:给定n,k,求Σi^k (i=1~n),对1e9+7取模.(n<=10^9,k<=10^6) 思路:令f(n)=Σi^k (i=1~n),则有f(n)-f(n-1)=n^k,说明f(n)的差分是n的k次多项式,则所求f(n)为n的k+1次多项式,利用拉格朗日插值公式,我们暴力计算n=0~k+1时的答案,代入公式,利用预处理的信息加速计算,总复杂度O(klogMOD). #include<cstdio> #define MOD…
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…
题目链接 CF 633 F. The Chocolate Spree 题解 维护子数答案 子数直径 子数最远点 单子数最长直径 (最长的 最远点+一条链) 讨论转移 代码 #include<vector> #include<cstdio> #include<algorithm> #define gc getchar() #define pc putchar #define int long long inline int read() { int x = 0,f = 1…
F. Yet Another Minimization Problem http://codeforces.com/contest/868/problem/F 题意: 给定一个长度为n的序列.你需要将它分为m段,每一段的代价为这一段内相同的数的对数,最小化代价总和. n<=100000,m<=20. 分析: f[k][j]=min{f[k-1][j]+cost(k,j,i)}; cost发现不能快速的算出.于是不能用类似单调队列+二分的方法来做了. 考虑分治,solve(Head,Tail,L…
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…