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

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

  1. #include <iostream>
  2. #include <string.h>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <queue>
  6. #include <assert.h>
  7. #include <math.h>
  8. #include <string>
  9. #include <algorithm>
  10. #include <functional>
  11.  
  12. #define SIGMA_SIZE 26
  13. #define lson rt<<1
  14. #define rson rt<<1|1
  15. #define lowbit(x) (x&-x)
  16. #define foe(i, a, b) for(int i=a; i<=b; i++)
  17. #define fo(i, a, b) for(int i=a; i<b; i++)
  18. #define pii pair<int,int>
  19. #pragma warning ( disable : 4996 )
  20.  
  21. using namespace std;
  22. typedef long long LL;
  23. inline LL LMax(LL a, LL b) { return a>b ? a : b; }
  24. inline LL LMin(LL a, LL b) { return a>b ? b : a; }
  25. inline LL lgcd(LL a, LL b) { return b == ? a : lgcd(b, a%b); }
  26. inline LL llcm(LL a, LL b) { return a / lgcd(a, b)*b; } //a*b = gcd*lcm
  27. inline int Max(int a, int b) { return a>b ? a : b; }
  28. inline int Min(int a, int b) { return a>b ? b : a; }
  29. inline int gcd(int a, int b) { return b == ? a : gcd(b, a%b); }
  30. inline int lcm(int a, int b) { return a / gcd(a, b)*b; } //a*b = gcd*lcm
  31. const LL INF = 0x3f3f3f3f3f3f3f3f;
  32. const LL mod = 1e9+;
  33. const double eps = 1e-;
  34. const int inf = 0x3f3f3f3f;
  35. const int maxk = 3e6 + ;
  36. const int maxn = 1e6+;
  37.  
  38. /// 注意mod,使用前须调用一次 polysum::init(int M);
  39. namespace polysum {
  40. #define rep(i,a,n) for (int i=a;i<n;i++)
  41. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  42. typedef long long ll;
  43. const ll mod = 1e9 + ; /// 取模值
  44. 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; }
  45.  
  46. const int D = ; /// 最高次限制
  47. ll a[D], f[D], g[D], p[D], p1[D], p2[D], b[D], h[D][], C[D];
  48. ll calcn(int d, ll *a, ll n) {
  49. if (n <= d) return a[n];
  50. p1[] = p2[] = ;
  51. rep(i, , d + ) {
  52. ll t = (n - i + mod) % mod;
  53. p1[i + ] = p1[i] * t%mod;
  54. }
  55. rep(i, , d + ) {
  56. ll t = (n - d + i + mod) % mod;
  57. p2[i + ] = p2[i] * t%mod;
  58. }
  59. ll ans = ;
  60. rep(i, , d + ) {
  61. ll t = g[i] * g[d - i] % mod*p1[i] % mod*p2[d - i] % mod*a[i] % mod;
  62. if ((d - i) & ) ans = (ans - t + mod) % mod;
  63. else ans = (ans + t) % mod;
  64. }
  65. return ans;
  66. }
  67. void init(int M) { /// M:最高次
  68. f[] = f[] = g[] = g[] = ;
  69. rep(i, , M + ) f[i] = f[i - ] * i%mod;
  70. g[M + ] = powmod(f[M + ], mod - );
  71. per(i, , M + ) g[i] = g[i + ] * (i + ) % mod;
  72. }
  73. ll polysum(ll n, ll *arr, ll m) { /// a[0].. a[m] \sum_{i=0}^{n-1} a[i]
  74. for (int i = ; i <= m; i++)
  75. a[i] = arr[i];
  76. a[m + ] = calcn(m, a, m + );
  77. rep(i, , m + ) a[i] = (a[i - ] + a[i]) % mod;
  78. return calcn(m + , a, n - );
  79. }
  80. ll qpolysum(ll R, ll n, ll *a, ll m) { /// a[0].. a[m] \sum_{i=0}^{n-1} a[i]*R^i
  81. if (R == ) return polysum(n, a, m);
  82. a[m + ] = calcn(m, a, m + );
  83. ll r = powmod(R, mod - ), p3 = , p4 = , c, ans;
  84. h[][] = ; h[][] = ;
  85. rep(i, , m + ) {
  86. h[i][] = (h[i - ][] + a[i - ])*r%mod;
  87. h[i][] = h[i - ][] * r%mod;
  88. }
  89. rep(i, , m + ) {
  90. ll t = g[i] * g[m + - i] % mod;
  91. if (i & ) p3 = ((p3 - h[i][] * t) % mod + mod) % mod, p4 = ((p4 - h[i][] * t) % mod + mod) % mod;
  92. else p3 = (p3 + h[i][] * t) % mod, p4 = (p4 + h[i][] * t) % mod;
  93. }
  94. c = powmod(p4, mod - )*(mod - p3) % mod;
  95. rep(i, , m + ) h[i][] = (h[i][] + h[i][] * c) % mod;
  96. rep(i, , m + ) C[i] = h[i][];
  97. ans = (calcn(m, C, n)*powmod(R, n) - c) % mod;
  98. if (ans<) ans += mod;
  99. return ans;
  100. }
  101. }
  102.  
  103. LL num[maxn];
  104. LL n, k;
  105.  
  106. void init()
  107. {
  108. for( int i = ; i <= k+; i++ )
  109. num[i] = polysum::powmod((LL)i+, k);
  110. }
  111.  
  112. int main(){
  113. cin >> n >> k;
  114.  
  115. polysum::init(k);
  116. init();
  117.  
  118. LL ans = polysum::polysum(n, num, k+)%mod;
  119. printf("%lld\n", ans);
  120. return ;
  121. }

【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. NX11.0和VS2013 创建NXOpen 开发模版失败解决方案【转载】

    转载自PLM之家论坛 NX11.0和VS2013 创建NXOpen 开发模版失败解决方案 首先我觉得这个可能是西门子疏忽,基本上每个大版本没有补丁前都有类似问题,下面来说说怎么解决吧.注意这里版本,N ...

  2. STM32F427VI 电流

  3. win7 设置双屏壁纸

    http://dualmonitortool.sourceforge.net/ http://www.displayfusion.com/Features/Wallpaper/ 以第一个软件为例: 1 ...

  4. CentOS部署软件and so on……

    CentOS各版本系统下载 CentOS下载地址:http://archive.kernel.org/centos-vault/ CentOS安装python3.7.2: 1.安装依赖包 yum in ...

  5. Restoring Road Network Floyd

    问题 C: Restoring Road Network 时间限制: 1 Sec  内存限制: 128 MB提交: 731  解决: 149[提交] [状态] [讨论版] [命题人:admin] 题目 ...

  6. USACO2005 City Skyline /// oj23401

    题目大意: Input * Line 1: Two space separated integers: N and W * Lines 2..N+1: Two space separated inte ...

  7. neo4j数据库迁移---------Neo4j数据库导入导出的方法

    Neo4j数据进行备份.还原.迁移的操作时,首先要关闭neo4j; /usr/share/neo4j/bin neo4j stop 如果出现 Neo4j not running 出现这种情况, Neo ...

  8. 005-Java运算符

    1.  求余符号,余数的符号是和被除数保持一致的. 2. 自增自减运算符不改变变量的数据类型. 逻辑运算符 逻辑与:& 逻辑或:| 逻辑非:! 短路与:&& 短路或:|| 逻辑 ...

  9. linq语句,常用的查询,模糊查询,实体查询

    查询: //List是要查询的实体列表的集合 List.FindAll(n => n.NAME == NAME),    //NAME变量是要查询的条件 模糊查询 List.FindAll(s ...

  10. PHP算法之整数转罗马数字

    罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值I 1V 5X 10L 50C 100D 500M 1000例如, 罗马数字 2 写做 II ,即为两个并列的 1.12 ...