码迷,mamicode.com
首页 > 其他好文 > 详细

快速幂

时间:2020-03-11 01:23:37      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:class   bit   int   ++   main   std   style   col   efi   

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define LL long long
 6 
 7 int main(){
 8     LL a,b,m;
 9     cin >> a >> b >> m;
10     LL ans = 1;
11     while(b){
12         if(b & 1) ans = ans * a % m;
13         a = a * a % m;
14         b >>= 1;
15     }
16     cout << ans << endl;
17     return 0;
18 }

 

快速幂

标签:class   bit   int   ++   main   std   style   col   efi   

原文地址:https://www.cnblogs.com/zhangqiling/p/12459695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!