//模指数运算
#include
#include
#include
using namespace std;
int main()
{
//输入;
int b;
cin >> b;
int n;
cin >> n;
int m;
cin >> m;
//二进制转换
int q = n;
int k = 0;
deque numbers;
while (q != 0)
{
numbers.push_front(q % 2);
q /= 2;
}
//转二进制结束,生成一个deque保存二进制数;
//当时为了顺序输出能输出正确所以低位保存二进制高位,高位deque保存二进制低位,用的是push_front
int x = 1;
long long int power = b%m;
auto j = numbers.size();
for (int i = j-1; i >=0; i--)
{
if (numbers[i] == 1)
x = (x*power) % m;
power = (power*power) % m;
}//快速模算法核心步骤
cout << x;
return 0;
}