#54296: 冪次運算


goldsu8826@gmail.com (412440660)


#include<iostream>
using  namespace std;
int main(){
long long B, P, M;
long long ans;
while(cin >> B >> P >> M){
if(P==0){
if(M == 1)cout << 0 << '\n';
else cout << 1 << '\n';
continue;
}
B=B%M;
ans =1;
do{
if(P&1) ans = ans*B %M;
B=B*B %M;
}while(P >>= 1);
cout << ans << '\n';
}
return 0;
}
#54297: Re: 冪次運算


goldsu8826@gmail.com (412440660)