#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a=m; x%=m; while(1){ if(n&1) v*=x; if(v>=m) f=1,v%=m; n>>=1; if(!n) break; x=x*x; if(x>=m) f=1,x%=m; } return v; } Int mtetra(Int a,Int n,Int m,Int &f){ assert(a!=0); if(m==1) return f=1; if(n==0) return 1; if(n==1) return a; Int z=mtetra(a,n-1,phi(m),f); Int r=mpow(a,z,m,f); return r+f*m; } //END CUT HERE //INSERT ABOVE HERE signed solve(){ Int a,n,m,f=0; cin>>a>>n>>m; cout<