题目链接 The Sum of the k-th Powers

其实我也不懂为什么这么做的……看了无数题解觉得好厉害哇……

 #include <bits/stdc++.h>

 using namespace std;

 #define rep(i, a, b)    for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) const int mod = ;
const int N = ; int v[N], p[N], f[N], r[N], b[N], c[N], d[N];
int n, m, ret, tmp, tot; inline int Pow(int a, int b){
int t = ;
for (; b; b >>= , a = 1LL * a * a % mod)
if (b & ) t = 1LL * t * a % mod;
return t;
} int main(){ scanf("%d%d", &n, &m); ++m; f[] = ;
rep(i, , m){
if (!v[i]){
f[i] = Pow(i, m - );
p[++tot] = i;
} rep(j, , tot){
if (i * p[j] > m) break;
v[i * p[j]] = ;
f[i * p[j]] = 1LL * f[i] * f[p[j]] % mod;
if (i % p[j] == ) break;
}
} rep(i, , m) (f[i] += f[i - ]) %= mod; if ((n %= mod) <= m) return * printf("%d\n", f[n]); r[] = r[] = ;
rep(i, , m) r[i] = 1LL * (mod - r[mod % i]) * (mod / i) % mod;
rep(i, , m) r[i] = 1LL * r[i - ] * r[i] % mod;
rep(i, , m + ) b[i] = (n - i + + mod) % mod; c[] = d[m + ] = ;
rep(i, , m + ) c[i] = 1LL * c[i - ] * b[i] % mod;
dec(i, m + , ) d[i] = 1LL * d[i + ] * b[i] % mod; rep(i, , m){
tmp = 1LL * f[i] * r[m - i] % mod * r[i] % mod * c[i] % mod * d[i + ] % mod;
if ((m - i) & ) (ret += mod - tmp) %= mod;
else (ret += tmp) %= mod;
} return * printf("%d\n", ret);
}

Codeforces 622F The Sum of the k-th Powers(数论)的更多相关文章

  1. Codeforces 622F The Sum of the k-th Powers

    Discription There are well-known formulas: , , . Also mathematicians found similar formulas for high ...

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

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

  3. Codeforces 622F The Sum of the k-th Powers ( 自然数幂和、拉格朗日插值法 )

    题目链接 题意 : 就是让你求个自然数幂和.最高次可达 1e6 .求和上限是 1e9 分析 :  题目给出了最高次 k = 1.2.3 时候的自然数幂和求和公式 可以发现求和公式的最高次都是 k+1 ...

  4. Codeforces 396B On Sum of Fractions 数论

    题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...

  5. codeforces 963A Alternating Sum

    codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) ...

  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. Codeforces 631E Product Sum 斜率优化

    我们先把问题分成两部分, 一部分是把元素往前移, 另一部分是把元素往后移.对于一个 i 后的一个位置, 我们考虑前面哪个移到这里来最优. 我们设最优值为val,   val = max(a[ j ] ...

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

  9. leetcode 862 shorest subarray with sum at least K

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

随机推荐

  1. angular4使用代理

    1. 在angular-cli项目根目录下创建proxy.config.json { "/api/v1": { "target": "http://1 ...

  2. set 方法总结整理

    #!/usr/bin/env python __author__ = "lrtao2010" #Python 3.7.0 集合常用方法 #集合是无序的,元素不能重复,元素只能是数字 ...

  3. Linux学习-systemctl 针对 timer 的配置文件

    如何使用 systemd 内建的 time 来处理各种任务呢? systemd.timer 的优势 在 archlinux 的官网 wiki 上面有提到,为啥要使用 systemd.timer 呢? ...

  4. 教你玩App怎么赚钱(一)

    在看这篇文章之前,你一定要接受一下谋哥的观点:金钱就是价值流通的手段,不要高看了钱. 玩App怎么赚钱?貌似谋哥写的文章超级多,把这个最重要的忘记了.说实在的,我为啥要写“玩App"呢?其实 ...

  5. uiautomatorviewer打不开

    uiautomatorviewer打不开: 因为之前我下载的jdk版本为10,后来将jdk版本改为8之后就可以打开了.

  6. linux 复制部分文件到另外的文件夹

    show the command: |xargs -i cp {} ../ 或者指定目录 |xargs -i cp {} /home/peter

  7. [转]廖雪峰:datetime用法

    datetime是Python处理日期和时间的标准库. 获取当前日期和时间 我们先看如何获取当前日期和时间: >>> from datetime import datetime &g ...

  8. SQL中,WHERE HAVING的区别

    WHERE是约束声明,是用来约束选数据库中储存的值的,其是在查询返回结果集之前起作用,其必须作用于数据库中存在的值,因此不能用聚合函数(avg,sum,count等,因为这些函数返回的值并非数据库中储 ...

  9. IDE介绍以及Eclipse的简单使用

    一.IDE介绍 ①   什么是IDE? 1.  IDE全称是”Integrated Development Environment”,中文称为“集成开发环境”; 2.是用于提供程序开发环境的应用程序, ...

  10. 【转】C#学习之用迭代器实现枚举器

    http://www.cnblogs.com/zouzf/archive/2012/02/22/2362954.html 本人初学C#,本文仅供个人整理思路用,那里说得不对,请大家多多指教,万分感激! ...