您的位置:首页 > 其它

山东省第八届 ACM 省赛 G sum of power (简单快速幂)

2017-05-10 16:05 134 查看

2015: G sum of power

时间限制: 1 Sec  内存限制: 128 MB

提交: 13  解决: 5

[提交][状态][讨论版]

题目描述

Calculate  

mod (1e9+7) for given
n,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;
}






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM