#include<bits/stdc++.h> #define LL long long usingnamespace std; constint N = 20000000 + 5; int a, m, phi, p; char b[N]; intqpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = (LL)res * x % p; x = (LL)x * x % p; y >>= 1; } return res; } intmain() { scanf("%d%d%s", &a, &m, b + 1); phi = p = m; for (int i = 2, j; i <= m; ++i) if (m % i == 0) { phi = (LL)phi * (i - 1) / i; while (m % i == 0) m /= i; } int n = strlen(b + 1), bb = 0; if (n <= 8) //特判 { for (int i = 1; i <= n; ++i) bb = bb * 10 + b[i] - '0'; if (bb >= phi) bb = bb % phi + phi; } else { for (int i = 1; i <= n; ++i) bb = (bb * 10 + b[i] - '0') % phi; bb += phi; } printf("%d", qpow(a, bb)); return0; }