快速幂

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 using namespace std;
 5 typedef long long LL;
 6 LL pow_mod(LL a,LL p,LL n){
 7     if(p == 0) return 1;
 8     LL ans = pow_mod(a,p / 2,n);
 9     ans = ans * ans % n;
10     if(p % 2 == 1) ans = ans * a % n;
11     return ans;
12 }
13 int main(){
14     printf("%lld\n",pow_mod(3,5,1000));
15 }

 

posted @ 2016-08-24 23:56  Yan_Bin  阅读(106)  评论(0编辑  收藏  举报