#include <bits/stdc++.h>
using namespace std ;
const int N = 1e9 + 7 ;
int m, n, p ;
long long ans = 1 ;
int main() {
cin >> n >> m >> p ;
while ( p != 0 ) {
if ( p % 2 == 1 ) {
ans *= n ;
ans %= m ;
}
n *= n ;
n %= m ;
p /= 2 ;
}
cout << ans % m << '\n' ;
}