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值, ...
随机推荐
- vue 顶级组件
快 有时候懒的把一些通用组件写到template里面去,而业务中又需要用到,比如表示loading状态这样组件. 如果是这样的组件,可以选择把组件手动初始化,让组件在整个app生命周期中始终保持活跃. ...
- 流程控制之while循环for循环
流程控制之while循环1.什么是循环 循环就是重复做某件事2.为什么要有循环 为了让计算机能够具备人重复做某件事的能力3.如何用循环 while语法: while 条件: code1 code2 c ...
- Python基础(三)—— print()格式化输出变量
先举一个简单的例子说明: name = 'Jack' answer = input('你好,%s '%(name) + '你认识 Sean 不, 输入 yes or no\n') print('Sea ...
- Python学习笔记:wxPython(GUI图形用户界面)
wxPython是一套基于Python的第三方GUI插件,可用Python制作丰富的图形化界面程序. 安装:pip install wxPython 或者 网站下载安装https://pypi.org ...
- Python中变量的作用域
一.变量作用域的含义 变量的作用域说白了就是变量的值从哪里获取,或者说变量取值的地方 我们在写代码过程中会用到很多变量,这些变量会出现在各种代码块中,有的出现在函数块里,有的在函数块外,例如: def ...
- OpenCV中图像的读取,显示与保存
图像的读取,显示与保存 相关函数:cv2.imread().cv2.imshow().cv2.imwrite() 1.读入图像: 用cv2.imread()函数来读取图像,cv2.imread(路 ...
- Java装饰者模式(Decorator)
一.定义 装饰模式的设计理念主要是以对客户端透明的方式动态扩展对象的功能,是继承关系的一个替代(继承会产生大量的子类,而且代码有冗余).装饰模式可以在不创造更多子类的情况下,将对象的功能加以扩展.装饰 ...
- 在O(1)时间内删除链表结点 【微软面试100题 第六十题】
题目要求: 给定链表的头指针和一个结点指针,在O(1)时间删除该结点. 参考资料:剑指offer第13题. 题目分析: 有几种情况: 1.删除的结点是头结点,且链表不止一个结点: 2.删除的结点是头结 ...
- 计算n的阶乘(n!)末尾0的个数
题目: 给定一个正整数n,请计算n的阶乘n!末尾所含有“0”的个数. 举例: 5!=120,其末尾所含有的“0”的个数为1: 10!= 3628800,其末尾所含有的“0”的个数为2: 20!= 24 ...
- day01_09.你已学会编程
目前你已经学会编程: 学会变量,运算,控制,你就学会了编程,我擦?真的,假的? 1.打印1-100,自己试试看呗 <?php $num = 1; while($num<=100){ ech ...