CSU 1556 Jerry's trouble
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1556
Description
Jerry is caught by Tom. He was penned up in one room with a door, which only can be opened by its code. The code is the answer of the sum of the sequence of number written on the door. The type of the sequence of number is
But Jerry’s mathematics is poor, help him to escape from the room.
Input
There are some cases (about 500). For each case, there are two integer numbers n, m describe as above ( 1 <= n < 1 000 000, 1 <= m < 1000).
Output
For each case, you program will output the answer of the sum of the sequence of number (mod 1e9+7).
Sample Input
4 1
5 1
4 2
5 2
4 3
Sample Output
10
15
30
55
100
Hint
Source
题意:
看sample猜公式。QAQ
题解:
公式是 1^m + 2^m + ···· + n^m。用快速幂解决。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
//#define LOCAL
#define eps 0.0000001
#define LNF (1<<60)
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = +;
const int mod = 1e9+; LL qpow(LL a, LL b)
{
LL ans = ;
LL base = a;
while(b){
if(b&) ans = (ans * base)%mod;
b >>= ;
base = (base * base)%mod;
}
return ans;
}
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL int n,m;
while(~scanf("%d%d", &n, &m))
{
LL ans = ;
for(int i = ;i<=n;i++)
{
ans = (ans + qpow(i, m))%mod;
}
printf("%lld\n", ans);
}
return ;
}
CSU 1556 Jerry's trouble的更多相关文章
- 快速幂 --- CSU 1556: Jerry's trouble
		
Jerry's trouble Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1556 Mean: 略. ana ...
 - CSU - 1556 Jerry's trouble(高速幂取模)
		
[题目链接]:click here [题目大意]:计算x1^m+x2^m+..xn^m(1<=x1<=n)( 1 <= n < 1 000 000, 1 <= m < ...
 - csu 1556(快速幂)
		
1556: Jerry's trouble Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 787 Solved: 317[Submit][Statu ...
 - 【CSU 1556】Pseudoprime numbers
		
题 Description Jerry is caught by Tom. He was penned up in one room with a door, which only can be op ...
 - Contest2071 - 湖南多校对抗赛(2015.03.28)
		
Contest2071 - 湖南多校对抗赛(2015.03.28) 本次比赛试题由湖南大学ACM校队原创 http://acm.csu.edu.cn/OnlineJudge/contest.php?c ...
 - Jerry的Fiori原创文章合集
		
我曾经于2014年10月到2016年5月工作于SAP CRM Fiori应用的开发团队, 我所在的团队负责下列这8个Fiori应用的维护和持续开发: My Opportunities My Tasks ...
 - HDU 1556  线段树或树状数组,插段求点
		
1.HDU 1556 Color the ball 区间更新,单点查询 2.题意:n个气球,每次给(a,b)区间的气球涂一次色,问最后每个气球各涂了几次. (1)树状数组 总结:树状数组是一个查 ...
 - csu 1812: 三角形和矩形 凸包
		
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...
 - 【BZOJ-1863】trouble 皇帝的烦恼      二分 + DP
		
1863: [Zjoi2006]trouble 皇帝的烦恼 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 559 Solved: 295[Submit] ...
 
随机推荐
- 【HANA系列】SAP HANA快捷键大全
			
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA快捷键大全 ...
 - Bootstrap 学习笔记 项目实战 首页内容介绍 上
			
效果图: HTML代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset ...
 - gradle使用方法
			
创建一个项目 你可以通过创建一个build.gradle的文件来开始一个项目,然后可以向文件中加入构建逻辑. $ mkdir basic-demo $ cd basic-demo $ touch bu ...
 - docker--docker版本以及安装
			
3 docker 版本以及安装 3.1 docker 版本介绍 https://www.docker.com/ Docker CE 在 17.03 版本之前叫 Docker Engine, Docke ...
 - python 安装成linux中的systemd守护运行
			
参考文档1:https://blog.csdn.net/luckytanggu/article/details/53467687 参考文档2:https://www.jianshu.com/p/e14 ...
 - Hadoop运行模式:本地模式、伪分布模式、完全分布模式
			
1.本地模式:默认模式 - 不对配置文件进行修改. - 使用本地文件系统,而不是分布式文件系统. - Hadoop不会启动NameNode.DataNode.ResourceManager.NodeM ...
 - Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
			
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
 - Python 中的垃圾回收机制
			
GC作为现代编程语言的自动内存管理机制,专注于两件事:1. 找到内存中无用的垃圾资源 2. 清除这些垃圾并把内存让出来给其他对象使用.GC彻底把程序员从资源管理的重担中解放出来,让他们有更多的时间放在 ...
 - P1522 牛的旅行 (Floyd)
			
[题目描述] 请编程找出一条连接两个不同牧场的路径,使得连上这条路径后,这个更大的新牧场有最小的直径.输出在所有牧场中最小的可能的直径. [题目链接] https://www.luogu.org/pr ...
 - http请求报文格式(请求行、请求头、空行 和 请求包体)和响应报文格式(状态行、响应头部、空行 和 响应包体)
			
转载 出处 超文本传输协议(Hypertext Transfer Protocol,简称HTTP)是应用层协议.HTTP 是一种请求/响应式的协议,即一个客户端与服务器建立连接后,向服务器发送一个请求 ...