标签:csu 快速幂取模
【题目链接】:click here~~\
【题目大意】:计算x1^m+x2^m+..xn^m(1<=x1<=n)( 1 <= n < 1 000 000, 1 <= m < 1000)
【解题思路】:
快速幂取模
代码:
#include<bits/stdc++.h> #define LL long long using namespace std; const LL mod=(LL)1e9+7; LL pow_mod(LL a,LL p,LL n) { if(p==0) return 1; LL ans=pow_mod(a,p/2,n); ans=ans*ans%n; if(p&1) ans=ans*a%n; return ans; } int n,m; int main() { while(scanf("%d%d",&n,&m)!=EOF) { LL ans=0; for(int i=1; i<=n; i++) ans=(ans+pow_mod(i%mod,m,mod))%mod; printf("%lld\n",ans); } return 0; }
CSU - 1556 Jerry's trouble(快速幂取模)
标签:csu 快速幂取模
原文地址:http://blog.csdn.net/u013050857/article/details/46675323