Problem Description
Calculate mod (1000000000+7) for given n,m.
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
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
题意:求从1到n的整数的m次方的和
思路:快速幂,要注意用long loog
代码:
#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;
}