#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(n){ if(n&1) v*=x; if(v>=m) flg=1,v%=m; x=x*x%m; n>>=1; } return v+flg*m; } Int mtetra(Int a,Int n,Int m,Int &flg){ assert(a!=0); if(m==1) return flg=1,0; if(n==0) return 1; if(n==1) return a; Int z=mtetra(a,n-1,phi(m),flg); return mpow(a,z,m)+flg*m; } //END CUT HERE //INSERT ABOVE HERE signed solve(){ Int a,n,m,f=0; cin>>a>>n>>m; cout<