sum of power

Problem Description

Calculate  mod (1000000000+7) for given nm.

Input

Input contains two integers n,m(1≤n≤1000,0≤m≤10).

Output

Output the answer in a single line.

Sample Input

10 0

Sample Output

10

Hint

Source

"Inspur Cup" Shandong Province 8th ACM College Student Programming Competition (Thanks to Qingdao University of Science and Technology)

Question: Find the sum of the m-th powers of the integers from 1 to n

Idea: fast power, pay attention to use long loog

Code:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define mod 1000000007
using namespace std;
typedef long long LL;
LL q_pow(LL x,LL y){
	LL ans=1;
	while(y){
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans%mod;
}
int main(){
	LL n,m;
	scanf("%lld%lld",&n,&m);
	LL ans=0;
	for(LL i=1;i<=n;i++){
		ans+=q_pow(i,m)%mod;
		ans% = mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325900064&siteId=291194637
sum