2015: G sum of power
时间限制: 1 Sec 内存限制: 128 MB提交: 13 解决: 5
[ 提交][ 状态][ 讨论版]
题目描述
Calculate mod (1e9+7) for givenn,m.
输入
Input contains two integers n,m(1≤n≤1000,0≤m≤10).
输出
Output the answer in a single line.
样例输入
10 0
样例输出
10
这题就是求个和---
直接套快速幂模板就能过。数据类型全用longlong。
上代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
LL qpow(LL a,LL b)///快速幂------
{
LL ans=1;
if(a==0)
{
return 0;
}
else
{
while(b)
{
if(b&1)ans=(a%mod)*(ans%mod);
b>>=1;
a=(a%mod)*(a%mod);
}
}
return ans;
}
int main()
{
LL n,m;///数据类型全用long long
while(~scanf("%lld %lld",&n,&m))
{
LL sum=0;
for(int i=1;i<=n;i++)
{
sum=(sum+qpow(i,m))%mod;
}
printf("%lld\n",sum);
}
return 0;
}