inlineintphi(int n){ int ans = 1, num = 1; for(int i = 2; i * i <= n; i++){ if (!(n % i)){ num = i - 1; n /= i; while(!(n % i)){ num *= i; n /= i; } ans *= num; } } if (n != 1){ ans *= n - 1; } return ans; }
inlineintqpow(int b, int p, int mod){ ll pow = b, temp = p, ans = 1; for ( ; temp; temp >>= 1){ if (temp & 1){ ans *= pow; if (ans > mod) ans %= mod; } pow *= pow; if (pow > mod) pow %= mod; } return ans % mod; }
inlineintread(int mod){ int x = 0, flag = 0; char c = getchar(); while(c < '0' || c > '9') continue; while(c >= '0' && c <= '9'){ x = (x << 3) + (x << 1) + (c ^ 48); if (x >= mod){ x %= mod; flag = 1; } c = getchar(); } return x + (flag ? mod : 0); }
inlineintphi(int n){ int ans = 1, num = 1; for(int i = 2; i * i <= n; i++){ if (!(n % i)){ num = i - 1; n /= i; while(!(n % i)){ num *= i; n /= i; } ans *= num; } } if (n != 1){ ans *= n - 1; } return ans; }
intmain(){ int a, b, mod, cs; scanf("%d%d ", &a, &b); mod = phi(b); cs = read(mod); printf("%d", qpow(a, cs, b)); return0; }