算法进阶指南(位运算)---a^b

题目链接:a^b

#include<iostream>

using namespace std;

int main(){
    int a,b,p;
    cin>>a>>b>>p;
    int ans=1%p;
    while(b){
        if(b&1) ans=ans*1ll*a%p; //b&1表示:二进制个位数为1的话
        a=a*1ll*a%p; 
        b>>=1; //右移
    }
    cout<<ans<<endl;
}
原文地址:https://www.cnblogs.com/bingers/p/13189962.html