您的位置:首页 > 其它

2017年ACM第八届山东省赛G题:sum of power

2017-10-06 15:22 351 查看

G: sum of power

题目描述

Calculate

mod (1000000000+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

题意:累加从 1 到 n 的 m次幂模
思路:不用快速幂都能过 还要什么思路。。。。。


#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std ;

#define mod 1000000007
#define LL long long

LL quick_mod(LL n , LL m){
LL result = 1 ;
while(m){
if(m&1){
result = (result * n )%mod ;
}
n = (n*n) %mod;
m>>=1 ;
}
return result %mod;
}

int main(){
int n , m ;
while(~scanf("%d%d" , &n , &m)){
LL result = 0  ;
for(int i=1 ; i<=n ; i++){
result = (result+quick_mod(i , m) ) %mod ;
}
printf("%lld\n" , result) ;
}
return 0 ;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std ;

#define LL long long
#define mod 1000000007
int main(){
LL n , m ;
while(~scanf("%lld%lld" , &n , &m)){
LL result = 0 ;
for(int i=1 ; i<= n ; i++){
LL num = 1 ;
for(int j=1 ; j<=m ; j++){
num = num * i %mod ; // i ^ m % mod
}
result = (result + num ) % mod ;
}
printf("%lld\n" , result) ;
}
return 0 ;
}



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