b,e,m;main(r){for(;~scanf("%d%d%d",&b,&e,&m);printf("%d\n",r))for(r=1;e&1?r=1ll*r*b%m:0,b=1ll*b*b%m,e/=2;);}