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.
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).
For each case, you program will output the answer of the sum of the sequence of number (mod 1e9+7).
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
long long int q=1e9+7;
long long int mix(long long int a, long long int m)
{
if(m==0) return 1;
long long int sum=1;
while(m)
{
if(m%2)
sum=(sum*a) % q;
a=(a*a)%q;
m/=2;
}
return sum;
}
int main()
{
long long int n=0, m=0;
while(scanf("%lld%I64d", &n, &m)!=EOF)
{
long long int ans=0;
for(int i=1; i<=n; i++)
{
ans=(ans+mix(i,m))% q;
}
printf("%lld\n", ans);
}
return 0;
}