#include #include #include using namespace std; typedef long long LL; LL g,p,A,B,a,b,n,m,inv; map mp; inline LL ksm(LL a,LL b) { LL res=1; for(;b;b>>=1,a=a*a%p) b&1?res=res*a%p:0; return res; } inline LL BSGS(LL A,LL B) { A%=p; B%=p; for(int i=0;i0) { scanf("%lld%lld",&A,&B); //printf("a=%d b=%d\n",a,b); printf("%lld\n",ksm(B,BSGS(g,A))%p); } return 0; }