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(快速幂)的更多相关文章

  1. 快速幂 --- CSU 1556: Jerry's trouble

    Jerry's trouble Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1556 Mean: 略. ana ...

  2. CSU 1556 Jerry's trouble

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

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

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

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

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

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

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

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

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

  7. GDUFE-OJ 1203x的y次方的最后三位数 快速幂

    嘿嘿今天学了快速幂也~~ Problem Description: 求x的y次方的最后三位数 . Input: 一个两位数x和一个两位数y. Output: 输出x的y次方的后三位数. Sample ...

  8. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

  9. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

随机推荐

  1. 【ZJOI2005】沼泽鳄鱼 题解报告

    题目描述 潘塔纳尔沼泽地号称世界上最大的一块湿地,它地位于巴西中部马托格罗索州的南部地区.每当雨季来临,这里碧波荡漾.生机盎然,引来不少游客. 为了让游玩更有情趣,人们在池塘的中央建设了几座石墩和石桥 ...

  2. Linux之选取信息命令介绍与应用20170331

    在介绍选取信息命令之前,说一下管道符“|”与tr命令,因为在使用多个命令一起的时候经常用到它. 一.利用Linux所提供的管道符“|”将两个命令隔开,管道符左边命令的输出就会作为管道符右边命令的输入. ...

  3. OpenCV(C++版)图像读取,创建,复制,保存,显示

    http://blog.163.com/yuyang_tech/blog/static/21605008320132642254689/ 一个小例子: #include "stdafx.h& ...

  4. ss命令用法小记

    By francis_hao    Nov 4,2017   ss是一个查看socket的实用工具 概要 ss [options] [ FILTER ]   描述 ss可以查看socket的统计信息, ...

  5. PostgreSQL 传统 hash 分区方法和性能

    背景 除了传统的基于trigger和rule的分区,PostgreSQL 10开始已经内置了分区功能(目前仅支持list和range),使用pg_pathman则支持hash分区. 从性能角度,目前最 ...

  6. 2016-2017 ACM-ICPC East Central North America Regional Contest (ECNA 2016) F 区间dp

    Problem F Removal GameBobby Roberts is totally bored in his algorithms class, so he’s developed a li ...

  7. IOS性能调优系列:使用Time Profiler发现性能瓶颈

    硬广:<IOS性能调优系列>第五篇,预计会有二十多篇,持续更新,欢迎关注. 之前四篇都是关注于内存方面,分析了内存泄漏.僵尸对象.内存分配,本篇介绍Time Profiler工具的使用,开 ...

  8. python 删除文件/夹

    原文 : http://www.cnblogs.com/SophiaTang/archive/2012/01/16/2323467.html import os 删除文件: os.remove() 删 ...

  9. HTML5-Y音频与视频

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. VS Code 配置 C/C++ 环境

    写作原因 微软的 VSCode 一直以来为人诟病的一个问题就是对于 C/C++ 工程的编译以及调试支持度有限,配置起来比较复杂,但是 vscode-cpptools 团队经过一段时间的 bug 修复之 ...