csu 1556(快速幂)
1556: Jerry's trouble
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 787 Solved: 317
[Submit][Status][Web Board]
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 题意:求解 (1^m+2^m+...+n^m)%mod
题解:快速幂
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL mod = ;
LL pow_mod(LL a,LL n){
LL ans = ;
while(n){
if(n&) ans = ans*a%mod;
a = a*a%mod;
n>>=;
}
return ans;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
LL res = ;
for(int i=;i<=n;i++){
res = (res+pow_mod(i,m))%mod;
}
printf("%lld\n",res);
}
}
csu 1556(快速幂)的更多相关文章
- 快速幂 --- 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
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1556 Description Jerry is caught by Tom. He ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3. ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- GDUFE-OJ 1203x的y次方的最后三位数 快速幂
嘿嘿今天学了快速幂也~~ Problem Description: 求x的y次方的最后三位数 . Input: 一个两位数x和一个两位数y. Output: 输出x的y次方的后三位数. Sample ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
随机推荐
- ping: unknown host 解决办法
如果ping命令返回如下错误,那主要的可能性就是系统的DNS设置有误. [root@CentOS5 ~]# ping www.sina.com.cn ping: unknown host www.si ...
- 【原创】【2】rich editor系列教程。了解document.execommand操作,保存丢失的range,实时反馈样式给工具栏
[原创][2]rich editor系列教程.了解document.execommand操作,保存丢失的range,实时反馈样式给工具栏 索引目录:http://www.cnblogs.com/hen ...
- 【HEOI 2018】制胡窜
转载请注明出处:http://www.cnblogs.com/TSHugh/p/8779709.html YJQ的题解把思路介绍得很明白,只不过有些细节说得还是太笼统了(不过正经的题解就应该这个样子吧 ...
- 使用OpenCV进行标定(转载)
转载自牛猫靖 http://www.cnblogs.com/2008nmj/p/6278076.html 使用OpenCV进行相机标定 1. 使用OpenCV进行标定 相机已经有很长一段历史了.但是 ...
- 手脱FSG v1.33
1.载入PEID FSG v1.33 (Eng) -> dulek/xt 2.载入OD,先F8跟一会 004103E3 > BE A4014000 mov esi,fsg1_33.0040 ...
- Android的静默安装
原文 Android的静默安装似乎是一个很有趣很诱人的东西,但是,用普通做法,如果手机没有root权限的话,似乎很难实现静默安装,因为Android并不提供显示的Intent调用,一般是通过以下方式安 ...
- 前端PHP入门-021-重点日期函数之日期验证函数
checkdate可以判断一个输出的日期是否有效. 在实际的工作中,我们需要经常用于检测常用于用户提交表单的数据验证. 函数的语法格式如下: bool checkdate ( int month,in ...
- codevs 1492 探案第二部
1492 探案第二部 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 我们伟大的 Sherlock·Holmes 先生最近遇上了一件相当棘手的案子,随 ...
- 树上的构造 树分治+树重心的性质 Codeforces Round #190 (Div. 2) E
http://codeforces.com/contest/322/problem/E E. Ciel the Commander time limit per test 1 second memor ...
- 图论&搜索:K短路-启发式搜索
判断第k短路的权值是否小于T 直接把队友的代码拿过来了,一定很经典 #include <iostream> #include <queue> #include <cstr ...