Codeforces 622F The Sum of the k-th Powers(数论)
题目链接 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(数论)的更多相关文章
- Codeforces 622F The Sum of the k-th Powers
Discription There are well-known formulas: , , . Also mathematicians found similar formulas for high ...
- codeforces 622F. The Sum of the k-th Powers 拉格朗日插值法
题目链接 求sigma(i : 1 to n)i^k. 为了做这个题这两天真是补了不少数论, 之前连乘法逆元都不知道... 关于拉格朗日插值法, 我是看的这里http://www.guokr.com/ ...
- Codeforces 622F The Sum of the k-th Powers ( 自然数幂和、拉格朗日插值法 )
题目链接 题意 : 就是让你求个自然数幂和.最高次可达 1e6 .求和上限是 1e9 分析 : 题目给出了最高次 k = 1.2.3 时候的自然数幂和求和公式 可以发现求和公式的最高次都是 k+1 ...
- Codeforces 396B On Sum of Fractions 数论
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...
- codeforces 963A Alternating Sum
codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) ...
- [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 ...
- Codeforces 631E Product Sum 斜率优化
我们先把问题分成两部分, 一部分是把元素往前移, 另一部分是把元素往后移.对于一个 i 后的一个位置, 我们考虑前面哪个移到这里来最优. 我们设最优值为val, val = max(a[ j ] ...
- 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 ...
- leetcode 862 shorest subarray with sum at least K
https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/ 首先回顾一下求max子数组的值的方法是:记录一个前缀min值, ...
随机推荐
- 解决linux不能解压rar格式压缩包
1download rarlinux-x64-5.3.0.tar.gz data package 2.tar xvf rarlinux-64-5.3.0.tar.gz 3. cd rar and th ...
- Buffered Channels and Worker Pools
原文链接:https://golangbot.com/buffered-channels-worker-pools/ buffered channels 带有缓冲区的channel 只有在缓冲区满之后 ...
- manjaro kde tim QQ
deepin-wine-tim
- uncaught exception 'NSInternalInconsistencyException, reason:[UITableViewController loadView] loaded the "Controller" nib but didn't get a UITableView
http://blog.csdn.net/ryantang03/article/details/7941058#reply 上面那篇文章是我查找的ios实现下拉刷新功能,在我下载完代码运行的过程中发现 ...
- BZOJ 3590: [Snoi2013]Quare
首先有一个性质,一个双联通图一定可以拆成一个小的双联通子图和一条链 一个点可以视为权值为0的双联通图或者一个点的链 状压DP,枚举子集 O(3^n*n^2) #include<cstdio> ...
- JAVA-基础(六) Java.io
由于IDEA相对于我这种新手来说,对学习JAVA还是比较方便,后记都移步到IDEA中进行基础学习 1.File(文件类) 尽管java.io定义的大多数类是实行流式操作的,File类不是.它直接处理文 ...
- webdriver高级应用- 启动FireFox的同时打开Firebug
1. 首先本机Firefox浏览器需要安装一下firebug插件,具体怎么安装这里不赘述,网上教程很多. 2. 具体自动化实现的代码如下: #encoding=utf-8 from selenium ...
- verilog 实现中值滤波
图像信号在形成.传输和记录的过程中,由于成像系统.传输介质.工作环境和记录设备等的固有缺陷,不可避免地产生各种类型的噪声,降低了图像的质量,进而影响后续处理(如边缘检测.图像分割.特征提取.模式识别等 ...
- SQL中,WHERE HAVING的区别
WHERE是约束声明,是用来约束选数据库中储存的值的,其是在查询返回结果集之前起作用,其必须作用于数据库中存在的值,因此不能用聚合函数(avg,sum,count等,因为这些函数返回的值并非数据库中储 ...
- 为什么要用全文搜索引擎:全文搜索引擎 VS 数据库管理系统
正文一:Full Text Search Engines vs. DBMS 发表于2009年 正文二:Elasticsearch - A High-Performance Full-Text Sea ...