题目链接: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的更多相关文章

  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&#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. Contest2071 - 湖南多校对抗赛(2015.03.28)

    Contest2071 - 湖南多校对抗赛(2015.03.28) 本次比赛试题由湖南大学ACM校队原创 http://acm.csu.edu.cn/OnlineJudge/contest.php?c ...

  6. Jerry的Fiori原创文章合集

    我曾经于2014年10月到2016年5月工作于SAP CRM Fiori应用的开发团队, 我所在的团队负责下列这8个Fiori应用的维护和持续开发: My Opportunities My Tasks ...

  7. HDU 1556 线段树或树状数组,插段求点

    1.HDU 1556  Color the ball   区间更新,单点查询 2.题意:n个气球,每次给(a,b)区间的气球涂一次色,问最后每个气球各涂了几次. (1)树状数组 总结:树状数组是一个查 ...

  8. csu 1812: 三角形和矩形 凸包

    传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...

  9. 【BZOJ-1863】trouble 皇帝的烦恼 二分 + DP

    1863: [Zjoi2006]trouble 皇帝的烦恼 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 559  Solved: 295[Submit] ...

随机推荐

  1. vue 父子component生命周期

    如今前端框架都流行组件化,页面元素都可以使用组件进行高度概括,那么处理组件之间的关系就如同处理页面架构一样重要.正确理解组件之间的关系,才能让代码按照我们与预料方式工作.最近参与了一个Vue.js的项 ...

  2. 20191103 《Spring5高级编程》笔记-第4章

    第4章 详述Spring配置和Spring Boot 4.2 管理bean生命周期 通常,有两个生命周期事件与bean特别相关:post-initialization和pre-destruction. ...

  3. mysql 函数 时间函数,数学函数,字符串函数,条件判断函数

    =========================================== mysql 相关函数 ============================================= ...

  4. New start-开始我的学习记录吧

    不知道从何说起,就从眼下的感想开始吧. 转行是一件不容易的事情! 今天是来北京学习Java的第41天.小测验了两次,一次51分,一次54分. 下午有学长过来分享了他的成长经历,感触很多.不是灌鸡汤,也 ...

  5. 通过FSDataOutputStream向HDFS上写数据

    FSDataOutputStream,这个类重载了很多write方法,用于写入很多类型的数据:比如字节数组,long,int,char等等. 像FSDataInputStream一样,要获得FSDat ...

  6. <每日一题> Day2:CodeForces-1141C.PolycarpRestoresPermutation(思维题)

    原题链接 参考代码: #include <iostream> #include <cstring> using namespace std; + , INF = 0x3f3f3 ...

  7. [2019杭电多校第三场][hdu6606]Distribution of books(线段树&&dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6606 题意为在n个数中选m(自选)个数,然后把m个数分成k块,使得每块数字之和最大的最小. 求数字和最 ...

  8. CSRF verification failed. Request aborted.错误解决办法

    在Django项目的页面,提交form表单POST请求时,会出现报错:CSRF verification failed. Request aborted. 需要在form表单中加:{% csrf_to ...

  9. Python 中的作用域?

    Python 中,一个变量的作用域总是由在代码中被赋值的地方所决定. 当 Python 遇到一个变量的话,它会按照这的顺序进行搜索:本地作用域(Local)--->当前作用域被嵌入的本地作用域( ...

  10. Java OO知识总结

    接着上一集    https://www.cnblogs.com/pdev/p/11288014.html       5. OO中的一些基本概念 继承 父类的非private方法自动被子类继承 cl ...