题目链接 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. 在windows7 32ibt安装MongoDB数据库的方法及连接失败解决方案

    参考 https://www.cnblogs.com/cnblogs-jcy/p/6734889.html http://yunkus.com/mongodb-install-config-in-wi ...

  2. python数据类型之列表(list)和其常用方法

    列表是python常用数据类型之一,是可变的,可由n = []创建,也可由n = list()创建,第一种方法更常用. 常用方法总结: # 创建方法 n = [] 或者 n = list() # in ...

  3. LeetCode(279)Perfect Squares

    题目 Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9 ...

  4. 利用Windbg深入理解变量的存储模型

    下面的是一个简单的测试程序,基本包括了所有的变量类型,包括静态的,常量的,全局的,本地的,还有new出来的 #include <iostream> using namespace std; ...

  5. 【12】Firefox 快捷键大全及更改和定制快捷键的方法

    [12]Firefox 快捷键大全及更改和定制快捷键的方法 答: Firefox 本身没有提供更改和定制快捷键的选项,若有需要,请安装扩展 Keyconfig 来解决.  安装地址如下: Keycon ...

  6. 你应该知道的.net平台下socket异步通讯(代码实例)

    1,首先添加两个windows窗体项目,一个作为服务端server,一个作为客户端Client 2,然后添加服务端代码,添加命名空间,界面上添加TextBox控件 using System.Net; ...

  7. SDOJ 1195 Zhenhuan

    描述 今日又在看甄嬛传,皇上觉得后宫们的勾心斗角太险恶了,有点不好,决定给每个妃子发丝带以让后宫之间和睦相处.皇上一共有N个后宫(标号为1~n),站成一个环形(1号与n号相邻),每个后宫想要ai个丝带 ...

  8. TOJ1550: Fiber Communications

    1550: Fiber Communications  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal ...

  9. 51nod1832 先序遍历与后序遍历

    对于给定的一个二叉树的先序遍历和后序遍历,输出有多少种满足条件的二叉树.两棵二叉树不同当且仅当对于某个x,x的左儿子编号不同或x的右儿子编号不同. Input 第一行一个正整数n(3<=n< ...

  10. 【mysql 优化 1】优化概述

    原文地址:Optimization Overview 数据库性能取决于几个数据库层面的因素,比如:表设计,查询语句,配置. 这些软件结构导致你必须在CPU和I/O 操作的硬件层面做到尽可能的最小化和高 ...