#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int b,m,tmp; //tmp表示指数
while(cin>>b>>tmp>>m)
{
int base = 0, top = 0, node[100], a = 1;
while(tmp)
{
node[top++] = tmp%2;
tmp = tmp/2;
}
while(base<top)
{
if(node[base]==0)
{
a = a % m;
b = b * b % m;
}
else
{
a = a * b % m;
b = b * b % m;
}
base++;
}
cout<<a<<endl;
}
}
计算结果: