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] ...
随机推荐
- JQuery weui 中的Popup (弹出层:底部)
//弹出层(从底部) <div id="bottomb" class="weui-popup__container popup-bottom"> & ...
- [19/05/06-星期一] JDBC(Java DataBase Connectivity,java数据库连接)_基本知识
一.概念 JDBC(Java Database Connectivity)为java开发者使用数据库提供了统一的编程接口,它由一组java类和接口组成.是java程序与数据库系统通信的标准API. J ...
- [2019杭电多校第三场][hdu6609]Find the answer(线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6609 大致题意是求出每个位置i最小需要将几个位置j变为0(j<i),使得$\sum_{j=1}^ ...
- Feign负载均衡
Feign是一个声明式的Web Service客户端,比Ribbon好用,默认也是轮巡.我们只需要使用Feign创建一个接口,并用注解就好了.如果你基于spring cloud发布一个接口,实际上就是 ...
- 该项目不知道如何运行配置文件 IIS Express。
项目右键属性-->调试 -->启动改为项目即可
- IIS是怎么处理多个请求的?
一,假设有一台服务器,它的IIS上部署有一个Web应用程序-S,可以通过浏览器或其他方式进行访问. 假设有A.B.C三台电脑同时访问网站S,IIS接收到3个HTTP请求,然后分别为三个请求 ...
- 跨域问题解决----NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost:11000' is therfore not allowed access'
NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost ...
- Scala本地安装
一.下载 https://www.scala-lang.org/download/ 这里我选择Scala2.10.4版本 二.安装 安装比较简单 和jdk类似 点击一路安装: 选择自己的路径 完成 ...
- jsp页面转换时间戳
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <fmt:fo ...
- python面向对象--类的内置函数
#isinstance(obj,cls)判断obj是否是类cls的实例 #issubclass(cls,cls1)判断cls是否是cls1的子类或派生类 class Foo: pass class B ...