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