a23=a16 * a^4 * a^2 * a^1
res=a^1
res*=a^2
res*=a^4
res*=a^16
...
#include<bits/stdc++.h> #define ll long long using namespace std; int main(){ ll a,b,p,res=1; cin>>a>>b>>p; while(b){ if(b&1)res=res*a%p;//当前位是1 a=a*a%p;//使得a顺次变成a^1 a^2 a^4 a^8 ... b/=2; } cout<<res<<endl; return 0; }