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的更多相关文章

  1. CSU 1556 Jerry's trouble

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1556 Description Jerry is caught by Tom. He ...

  2. CSU - 1556 Jerry&#39;s trouble(高速幂取模)

    [题目链接]:click here [题目大意]:计算x1^m+x2^m+..xn^m(1<=x1<=n)( 1 <= n < 1 000 000, 1 <= m < ...

  3. csu 1556(快速幂)

    1556: Jerry's trouble Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 787  Solved: 317[Submit][Statu ...

  4. 【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 ...

  5. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

  6. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  7. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  8. hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)

    题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3.                  ...

  9. Codeforces632E Thief in a Shop(NTT + 快速幂)

    题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...

随机推荐

  1. Halcon学习标定助手

    本文采用halcon标定助手进行标定. 第一步:打开标定助手. 第二步:对描述文件进行修改 具体:打开算子窗口,输入gen_caltab,进行描述文件修改. 参数XNum和YNum为7行*7列的圆,M ...

  2. 项“XXXXX.sln”已在选择的位置受源代码管理

    项“XXXXX.sln”已在选择的位置受源代码管理.如果尝试重新绑定已在 Microsoft Visual Studio 外部添加到源代码管理的项目,应使用“更改源代码管理”命令.如果是第一次添加此项 ...

  3. dapper 操作类封装

    using System; using System.Collections.Generic; using System.Data; using System.Data.SQLite; using S ...

  4. Mac 上面使用SVN的攻略

    参考网站: http://blog.csdn.net/q199109106q/article/details/8655204 SVN命令集: http://www.blogjava.net/jasmi ...

  5. [原]OpenGL基础教程(五)缓冲区数据更新方式

    1.glBufferSubData 适用于相同数据类型 void SetPositionY(float y){    vector<Vector3<float>>::itera ...

  6. redhat下mysql安装与使用

    1.安装 (1)查看是否安装 yum list installed mysql* (2)查看现有安装包 yum list mysql* (3)安装mysql服务器端 yum install mysql ...

  7. [AX2012 R3]关于Named user license report

    Named user license报表是用来统计各种授权类型用户数的,这里来看看报表数据具体是如何来的.这是一个SSRS的报表,最主要的数据源是来自于类SysUserLicenseCountRepo ...

  8. [转载]CSS教程:实例讲解定位Position

    http://www.missyuan.com/thread-395406-1-1.html 1. position:static 所有元素的默认定位都是:position:static,这意味着元素 ...

  9. saiku执行速度优化二

    上一篇文章介绍了添加filter可以加快查询速度.下面继续分析: 下面这个MDX语句: WITH SET [~FILTER] AS {[create_date].[create_date].[--]} ...

  10. Jquery实现ready()的源码

    function bindReady(){ if ( readyBound ) return; readyBound = true; // Mozilla, Opera and webkit nigh ...