您的位置:首页 > 其它

CSU 1556-Jerry's trouble(快速幂)

2015-12-07 21:57 239 查看

1556: Jerry's trouble

Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 741  Solved: 299[Submit][Status][WebBoard]

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 isBut 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
AC代码:
#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<cstdio>using namespace std;#define T 123#define inf 0x3f3f3f3f#define mod 1000000007typedef long long ll;int powMod(ll n,ll p){ll res = 1;while(p>0){if(p&1){res=(res*n)%mod;}p/=2;n=(n*n)%mod;}return res;}int main(){#ifdef zscfreopen("input.txt","r",stdin);#endifint n,m,i;while(~scanf("%d%d",&n,&m)){ll sum=1;for(i=2;i<=n;++i){sum=(sum+powMod(i,m))%mod;}printf("%lld\n",sum%mod);}return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  算法