用的dls的板子,因为看不懂调了好久...果然用别人的板子就是这么蛋疼- -||

num数组0~k+1储存了k+2个值,且这k+2个值是自然数i的k次方而不是次方和,dls的板子自己帮你算和的...搞得我弄了好久

 #include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <queue>
#include <assert.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#define foe(i, a, b) for(int i=a; i<=b; i++)
#define fo(i, a, b) for(int i=a; i<b; i++)
#define pii pair<int,int>
#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a, LL b) { return a>b ? a : b; }
inline LL LMin(LL a, LL b) { return a>b ? b : a; }
inline LL lgcd(LL a, LL b) { return b == ? a : lgcd(b, a%b); }
inline LL llcm(LL a, LL b) { return a / lgcd(a, b)*b; } //a*b = gcd*lcm
inline int Max(int a, int b) { return a>b ? a : b; }
inline int Min(int a, int b) { return a>b ? b : a; }
inline int gcd(int a, int b) { return b == ? a : gcd(b, a%b); }
inline int lcm(int a, int b) { return a / gcd(a, b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = 1e9+;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 3e6 + ;
const int maxn = 1e6+; /// 注意mod,使用前须调用一次 polysum::init(int M);
namespace polysum {
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
const ll mod = 1e9 + ; /// 取模值
ll powmod(ll a, ll b) { ll res = ; a %= mod; assert(b >= ); for (; b; b >>= ) { if (b & )res = res*a%mod; a = a*a%mod; }return res; } const int D = ; /// 最高次限制
ll a[D], f[D], g[D], p[D], p1[D], p2[D], b[D], h[D][], C[D];
ll calcn(int d, ll *a, ll n) {
if (n <= d) return a[n];
p1[] = p2[] = ;
rep(i, , d + ) {
ll t = (n - i + mod) % mod;
p1[i + ] = p1[i] * t%mod;
}
rep(i, , d + ) {
ll t = (n - d + i + mod) % mod;
p2[i + ] = p2[i] * t%mod;
}
ll ans = ;
rep(i, , d + ) {
ll t = g[i] * g[d - i] % mod*p1[i] % mod*p2[d - i] % mod*a[i] % mod;
if ((d - i) & ) ans = (ans - t + mod) % mod;
else ans = (ans + t) % mod;
}
return ans;
}
void init(int M) { /// M:最高次
f[] = f[] = g[] = g[] = ;
rep(i, , M + ) f[i] = f[i - ] * i%mod;
g[M + ] = powmod(f[M + ], mod - );
per(i, , M + ) g[i] = g[i + ] * (i + ) % mod;
}
ll polysum(ll n, ll *arr, ll m) { /// a[0].. a[m] \sum_{i=0}^{n-1} a[i]
for (int i = ; i <= m; i++)
a[i] = arr[i];
a[m + ] = calcn(m, a, m + );
rep(i, , m + ) a[i] = (a[i - ] + a[i]) % mod;
return calcn(m + , a, n - );
}
ll qpolysum(ll R, ll n, ll *a, ll m) { /// a[0].. a[m] \sum_{i=0}^{n-1} a[i]*R^i
if (R == ) return polysum(n, a, m);
a[m + ] = calcn(m, a, m + );
ll r = powmod(R, mod - ), p3 = , p4 = , c, ans;
h[][] = ; h[][] = ;
rep(i, , m + ) {
h[i][] = (h[i - ][] + a[i - ])*r%mod;
h[i][] = h[i - ][] * r%mod;
}
rep(i, , m + ) {
ll t = g[i] * g[m + - i] % mod;
if (i & ) p3 = ((p3 - h[i][] * t) % mod + mod) % mod, p4 = ((p4 - h[i][] * t) % mod + mod) % mod;
else p3 = (p3 + h[i][] * t) % mod, p4 = (p4 + h[i][] * t) % mod;
}
c = powmod(p4, mod - )*(mod - p3) % mod;
rep(i, , m + ) h[i][] = (h[i][] + h[i][] * c) % mod;
rep(i, , m + ) C[i] = h[i][];
ans = (calcn(m, C, n)*powmod(R, n) - c) % mod;
if (ans<) ans += mod;
return ans;
}
} LL num[maxn];
LL n, k; void init()
{
for( int i = ; i <= k+; i++ )
num[i] = polysum::powmod((LL)i+, k);
} int main(){
cin >> n >> k; polysum::init(k);
init(); LL ans = polysum::polysum(n, num, k+)%mod;
printf("%lld\n", ans);
return ;
}

【CF622F】The Sum of the k-th Powers (拉格朗日插值法)的更多相关文章

  1. Educational Codeforces Round 7 F. The Sum of the k-th Powers 拉格朗日插值法

    F. The Sum of the k-th Powers 题目连接: http://www.codeforces.com/contest/622/problem/F Description Ther ...

  2. codeforces 622F. The Sum of the k-th Powers 拉格朗日插值法

    题目链接 求sigma(i : 1 to n)i^k. 为了做这个题这两天真是补了不少数论, 之前连乘法逆元都不知道... 关于拉格朗日插值法, 我是看的这里http://www.guokr.com/ ...

  3. [题解] 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\ ...

  4. 解题:CF622F The Sum of the k-th Powers

    题面 TJOI2018出CF原题弱化版是不是有点太过分了?对,就是 TJOI2018 教科书般的亵渎 然而我这个问题只会那个题的范围的m^3做法 回忆一下1到n求和是二次的,平方求和公式是三次的,立方 ...

  5. Educational Codeforces Round 7 F - The Sum of the k-th Powers 拉格朗日插值

    The Sum of the k-th Powers There are well-known formulas: , , . Also mathematicians found similar fo ...

  6. [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 ...

  7. 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 ...

  8. leetcode 862 shorest subarray with sum at least K

    https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/ 首先回顾一下求max子数组的值的方法是:记录一个前缀min值, ...

  9. 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 ...

随机推荐

  1. 2019年12月12日英语学习-Will I Or Won't I ?

    这节英语课上的内容没记住多少东西,觉得这个主题太枯燥了,不过整堂课和外教沟通交流还是不错的,因为这节课就我一个学生.给我了充分的机会去张嘴交流互动. 也没记住什么东西,不知道写什么.只记住将要决定做某 ...

  2. C++的指针常量和常量指针

    这2个概念非常容易混淆,即使是老鸟,也有眩晕的时候,写此博文,加深记忆... 指针常量:一个指针,并且它是一个常量,它的值不许被改变: char *const p1 = "Hello!&qu ...

  3. 5天玩转C#并行和多线程编程 —— 第一天 认识Parallel 转载 https://www.cnblogs.com/yunfeifei/p/3993401.html

    5天玩转C#并行和多线程编程系列文章目录 5天玩转C#并行和多线程编程 —— 第一天 认识Parallel 5天玩转C#并行和多线程编程 —— 第二天 并行集合和PLinq 5天玩转C#并行和多线程编 ...

  4. HTML_标签

    <!--HTML:1.概念:最基础的网页开发语言Hyper Text Markup Language 超文本标记语言超文本:超文本是用超链接的方法,将各种不同空间的文字信息组织在一起的网状文本. ...

  5. std::unorder_set你插入元素的顺序不一定就是元素在里面的元素

    去看了下cppreference,里面写了 根据哈希值排序了

  6. php 执行mysql inset 指令无效

    网数据库里插入一条 inset into je_user("name","va") values("df","12"), ...

  7. java 对象转Map方法Demo

    /** * 用于对Object进行解析并且转换成Map键值对的形式 * */ public class ObjectUtils { private static final String JAVAP ...

  8. ElasticSearch 增删改查

    HTTP 协议本身语义:GET 获取资源.POST 新建资源(也可以用于更新资源).PUT 更新资源.DELETE 删除资源. ES通过HTTP Restful方式管理数据:1.格式:#操作 /ind ...

  9. digitalpersona 开发

    一 下载 sdk : https://codeload.github.com/iamonuwa/Digital-Persona-SDK/zip/master 二 解压后,安装SDK 三 找到安装目录( ...

  10. 【学术篇】SDOI2011 计算器

    好一道三合一...(然而被我做成了四合一) 其实1 2 3是独立的OvO 然后就可以逐个分析了... 1 快速幂..就不说了..(我省选的时候有这么水的20pts部分分么←_← 2 两种做法(写在标题 ...