题目AcWing 89的C++代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL fastPow(LL a,LL b,LL p) {
LL ans=1;
while(b) {
if(b & 1) ans=ans*a%p;
a=a*a%p;
b>>=1;
}
return ans%p; //not return ans
}
int main() {
LL a,b,p;
cin>>a>>b>>p;
cout<<fastPow(a,b,p)<<endl;
return 0;
}
/*
in:
3 2 7
out:
2
*/