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] ...
随机推荐
- mooc-IDEA postfix--007
十三.IntelliJ IDEA -postfix 代码中输入: 总结常用的postfix: 1.for (<=>100.fori) 2.sout (<=>System.ou ...
- oracle-第N篇加强专题
1.Oracle数据库日期类型 1>日期的比较 2>日期格式化 2.Oracle字符串类型 1>常用函数
- Maven-maven插件(1)添加主类信息到MANIFEST.MF
1.以前面的HelloWorld项目为例,在pom.xml中添加如下代码,指定插件 <build> <plugins> <plugin> <groupId&g ...
- ARM汇编2
一. 数据处理汇编指令 1.1. 数据传输指令 1.1.1. mov(Move) 指令 示例:mov r0, r0, LSL#3 ; r0 = r0* 8 mov pc, r ...
- Python3之Django Web框架中间件???
主要用来处理页面的登录验验.跨站请求伪造防御.日志记录.session设置,权限管理等
- 从安装linux(centos7.6)系统到部署springboot java程序到k8s(大纲)
本文说明从安装linux系统开始,一直到在k8s运行springboot程序全过程 本文假设在自己电脑操作,因此linux系统使用vmware虚拟机,linux发行版使用centos 7.6.1810 ...
- B.Petr and a Combination Lock
https://codeforces.com/contest/1097/problem/A Petr and a Combination Lock time limit per test 1 seco ...
- 搜索(DFS)---查找最大连通面积
查找最大的连通面积 695. Max Area of Island (Medium) [[0,0,1,0,0,0,0,1,0,0,0,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0] ...
- wxpython模板程序,包括各个实例
#coding=utf-8 import wx import time import os class MyApp(wx.App): def __init__(self): wx.App.__init ...
- Win10系统下插入耳机前面板无声后面板有声的处理
问题描述: 当耳机插入后面板绿色口(注意:耳机扬声器为绿色口,红色为话筒麦克风:前后面板一样):可以听到声音,但是转到前面板插入后,无声音:调出声音面板发现声音可随音度波动 处理步骤: 1.保证插牢接 ...