CSU - 1556 Jerry's trouble(快速幂)
来源:互联网 发布:蝎子网络第四季 编辑:程序博客网 时间:2024/06/05 18:27
Jerry's trouble
Time Limit: 10000MS Memory Limit: 262144KB 64bit IO Format: %lld & %llu
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 15 14 25 24 3
Sample Output
10153055100
题意:给出两个数,n 和 m, 求 1~n 之间每个数的 m 次幂的和,再取模
思路:快速幂
<span style="font-size:18px;">#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <string>#include <algorithm>#include <queue>#include <stack>using namespace std;#define ll long longconst double PI = acos(-1.0);const double e = 2.718281828459;const double eps = 1e-8;const ll MOD = 1e9+7;ll pow_mod(ll n, ll m) { ll res = 1; while(m) { if(m&1) res = res*n%MOD; n = n*n%MOD; m >>= 1; } return res;}int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ll n, m; ll ans; while(cin>>n>>m) { ans = 0; for(ll i = 1; i <= n; i++) { ans += pow_mod(i, m); ans %= MOD; } cout<<ans<<endl; } return 0;}</span>
0 0
- csu 1556: Jerry's trouble(快速幂)
- CSU - 1556 Jerry's trouble(快速幂)
- CSU - 1556 Jerry's trouble(快速幂取模)
- CSU 1556-Jerry's trouble(快速幂)
- 快速幂 --- CSU 1556: Jerry's trouble
- csu 1556: Jerry's trouble (快速幂取模)
- 湖南多校对抗赛---Jerry's trouble
- 湖南多校对抗赛3.28 J - Jerry's trouble
- CSU 1556 快速幂
- CSU 1658 IQ of XUEXX’s descendants 矩阵快速幂
- Jerry(Yahoo) 's speech
- Jerry's Tom
- codeforces626D . Jerry's Protest (概率)
- king's trouble II
- king's trouble II
- king's trouble I
- king's trouble I
- Codeforces 626D Jerry's Protest 【概率】
- 获取Class对象的三种获取方式:
- 日语学习之沪江N3基础 20150620 -4
- oj刷题——第十五周C++习题 对象转换
- 杭电 ACM HDU Train Problem I
- 列表中li标签设置margin在IE6和IE7中第一个行失效的解决方法
- CSU - 1556 Jerry's trouble(快速幂)
- Android学习第三课:I/O文件读写操作(一)
- JavaScript里call,apply,bind方法简介
- USACO——Milking Cows 挤牛奶
- Spring中的AOP简述
- win7硬盘安装ubuntu双系统的方法
- 游戏有这么好玩么?
- 面向对象技术学习笔记3 领域建模
- leetcode--Roman to Integer