Problem J: Jerry's trouble
Time Limit: 10 Sec
Memory Limit: 256 MB
Submit: 94 Solved: 44
[ 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
HINT
#include<algorithm>
#include<iostream>
#include<limits.h>
#include<stdlib.h>
#include<string.h>
#include<cstring>
#include<iomanip>
#include<stdio.h>
#include<bitset>
#include<cctype>
#include<math.h>
#include<string>
#include<time.h>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#define LL long long
using namespace std;
const LL mod = 1e9 + 7;
const double PI = acos(-1.0);
const double E = exp(1);
const int M = 10005;
LL power(LL x, LL n)
{
LL ans = 1;
while(n){
if(n & 1)
ans = ans * x % mod;
x = x * x % mod;
n >>= 1;
}
return ans;
}
int main()
{
int n, k;
while( cin >> n >> k )
{
LL ans = 0;
for(LL i = 1; i <= n; ++i)
ans += power(i,k) % mod;
cout << ans % mod << endl;
}
return 0;
}