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

快速幂取模

时间:2019-09-17 14:44:06      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:turn   return   while   进制   运算   pow   快速幂   ret   fine   

把幂转换为二进制进行运算

快速幂取模

#define LL long long
LL pow_mod(LL a, LL b, LL p){//a的b次方求余p
    LL ret = 1;
    while(b){
        if(b & 1) ret = (ret * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return ret;
}

快速幂取模

标签:turn   return   while   进制   运算   pow   快速幂   ret   fine   

原文地址:https://www.cnblogs.com/Emcikem/p/11533552.html

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