#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int v, w; }; ll MOD = 1000000009; ll _MOD = 1000000009; double EPS = 1e-10; int euler[2001]; int f(int A, int N, int M) { if (N == 0) return 1 % M; int x = f(A, N - 1, euler[N]); A %= M; int res = 1 % M; for (; x; x /= 2) { if (x % 2) res = res * A % M; A = A * A % M; } return res; } int main() { for (int i = 0; i <= 2000; i++) euler[i] = i; for (int i = 2; i <= 2000; i++) if (euler[i] == i) for (int j = i; j <= 2000; j += i) euler[j] = euler[j] / i * (i - 1); int A, N, M; cin >> A >> N >> M; cout << f(A, N, M) << endl; }