快速幂 --- CSU 1556: Jerry's trouble
Jerry's trouble
Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1556
Mean:
略。
analyse:
水题,直接快速幂。
Time complexity: O(n)
Source code:
// Memory Time
// 1347K 0MS
// by : crazyacking
// 2015-03-29-19.18
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define MAXN 1000010
#define LL long long
using namespace std;
const LL MOD=1e9+; LL quick_pow(LL a,LL b,LL m)
{
LL ans=;
while(b)
{
if(b&)
{
ans*=a;
ans%=m;
}
a*=a;
a%=m;
b/=;
}
return ans%m;
} int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
// freopen("C:\\Users\\Devin\\Desktop\\cin.cpp","r",stdin);
// freopen("C:\\Users\\Devin\\Desktop\\cout.cpp","w",stdout);
LL n,m;
while(cin>>n>>m)
{
LL sum=;
for(int i=;i<=n;++i)
{
sum+=quick_pow(i,m,MOD);
sum%=MOD;
}
cout<<sum%MOD<<endl;
}
return ;
}
/* */ /**************************************************************
Problem: 1556
User: crazyacking
Language: C++
Result: Accepted
Time:2704 ms
Memory:1476 kb
****************************************************************/
快速幂 --- CSU 1556: Jerry's trouble的更多相关文章
- CSU 1556 Jerry's trouble
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1556 Description Jerry is caught by Tom. He ...
- 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 ...
- 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
- 矩阵快速幂 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 ...
随机推荐
- 一篇不错的讲解Java异常的文章(转载)原作者已没法考证
六种异常处理的陋习 你觉得自己是一个Java专家吗?是否肯定自己已经全面掌握了Java的异常处理机制?在下面这段代码中,你能够迅速找出异常处理的六个问题吗? 1 OutputStreamWriter ...
- 使用dynamic类型改进反射
首先还是声明一下,使用场景: 1.如果编译时函数名称确定,对象类型运行时确定,那么运用dynamic是一个好主意.2.如果编译时函数名称确定,对象类型在编译时也确定,那就既不需要反射也不需要dynam ...
- 博为iHospital-HIS医院信息系统产品系列
博为软件iHospital-HIS产品系列式面向大中型医院应用的完整医院流程信息化产品,覆盖了医院主要的业务流程,管理职能,和病人在医院诊疗的各个环节.将医院流程的优化与软件系统完美结合,为建立数字化 ...
- CEF 相关资料
理解WebKit和Chromium: Content API和CEF3 http://blog.csdn.net/milado_nju/article/details/7455373 如何将Chrom ...
- pecl install imagick
steven@server:/var/www$ sudo pecl install imagickdownloading imagick-2.3.0.tgz ...Starting to downlo ...
- 整理PHP_YII环境安装遇到的一些问题
安装yii遇到的一些问题 操作环境 一.Permissiondenied问题 在终端执行如下命令(注意因为是本地测试环境不需要考虑太多权限问题,如果正式环境请慎重) sudo chmod -R o+r ...
- IOS开发 图形绘制,绘制线条,矩形,和垂直和居中绘制文字
概述 吐槽下IOS下 的图形绘图,代码冗长,不得不自己重新封装方法.整理形成本文. 绘制线 // 绘制直线 + (void)toDrawLineFromX:(CGFloat)x1 Y:(CGFloat ...
- Science上发表的超赞聚类算法
本博客已经迁往http://www.kemaswill.com/, 博客园这边也会继续更新, 欢迎关注~ 作者(Alex Rodriguez, Alessandro Laio)提出了一种很简洁优美的聚 ...
- linux 系统运维
Linux 系统监控1.进程 查看所有进程 ps -ef ps -ef |grep nginx 结束进程 # 结束进程号为5031 kill -g 5031 # 结束 ...
- react-native SyntaxError xxxxx/xx.js:Unexpected token (23:24)
在运行react-native项目时提示 SyntaxError xxxxx/xx.js:Unexpected token (23:24) 我这边的问题原因:jsx语法错误,解决办法就是认真排查代码然 ...