import std.stdio;void main(){for(long a,b,c,k;~scanf("%d%d%d",&a,&b,&c);printf("%d ",k))for(k=1;b;b/=2)b%2?k=k*a%c:0,a=a*a%c;}