Calculate mod (1000000000+7) for given n,m.
标签:img space 技术分享 names col single efi logs integer
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 ;
}
2017年ACM第八届山东省赛G题:sum of power
标签:img space 技术分享 names col single efi logs integer
原文地址:http://www.cnblogs.com/yi-ye-zhi-qiu/p/7631592.html