题目链接 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. Pytorch学习(一)—— 自动求导机制

    现在对 CNN 有了一定的了解,同时在 GitHub 上找了几个 examples 来学习,对网络的搭建有了笼统地认识,但是发现有好多基础 pytorch 的知识需要补习,所以慢慢从官网 API进行学 ...

  2. POJ:2955-Brackets(经典:括号匹配)

    传送门:http://poj.org/problem?id=2955 Brackets Time Limit: 1000MS Memory Limit: 65536K Description We g ...

  3. Selenium2用最简xpath查找元素

    什么是xpath? 来自百度百科的解释:XPath即为XML路径语言,它是一种用来确定XML(标准通用标记语言的子集)文档中某部分位置的语言.XPath基于XML的树状结构,提供在数据结构树中找寻节点 ...

  4. myeclipse中hibernate生成映射文件

    在hibernate中,每个数据表对应的其实是一个实体类,每个实体类有一个对应的hbm.xml配置文件匹配,myeclipse中有个MyEclipse Database Explorer视图,它提供了 ...

  5. git仓库删除所有提交历史记录

    stackoverflow原问题地址:http://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-g ...

  6. 树链剖分 - Luogu 3384【模板】树链剖分

    [模板]树链剖分 题目描述 已知一棵包含N个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作: 操作1: 格式: 1 x y z 表示将树从x到y结点最短路径上所有节点的值都加上z 操 ...

  7. PHP smarty模版引擎基本安装

    环境:  PHP5.2 以上版本 先去官网下载smarty模版引擎的库文件到你的电脑或服务器上 smarty官方网站库文件下载地址: https://www.smarty.net/download 下 ...

  8. Synergy 使用方法备忘

    Synergy 是 Symless 公司推出的「鼠标键盘共享软件」(mouse and keyboard sharing software),其功能还包括「共享剪贴板」(sharing clipboa ...

  9. VK Cup 2016 - Qualification Round 1——A. Voting for Photos(queue+map)

    A. Voting for Photos time limit per test 1 second memory limit per test 256 megabytes input standard ...

  10. HDU——1205吃糖果(鸽巢原理)

    吃糖果 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submis ...