#include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int M=1e7+10; LL qmul(LL a,LL b,LL mod){ LL ans=0; if(b<0){a=-a;b=-b;} while(b>0) { if(b&1) ans=(ans+a)%mod; a=(a+a)%mod; b>>=1; } return ans; } LL qpow(LL a, LL b, LL mod){ if(b==0)return 1ll; LL ans=1; while(b>0){ if(b&1) ans=ans*a%mod;//ans=qmul(ans,a,mod); a=a*a%mod;//a=qmul(a,a,mod); b>>=1; } return ans; } LL gcd(LL a,LL b){ while(b){ LL t=a%b; a=b; b=t; } return b; } LL exgcd(LL a,LL b,LL &x,LL &y){ if(b == 0){ x = 1, y = 0; return a; } LL d = exgcd(b, a%b, x, y); LL t = y; y = x - y * (a / b); x = t; return d; } LL solveLinear(LL a,LL b,LL p){//ax=b mod p a=(a%p+p)%p;b=(b%p+p)%p; LL x,y; LL d=exgcd(a,p,x,y); //printf("d=%lld x=%lld y=%lld\n",d,x,y); if(b%d!=0) return -1; return ((b/d)*x%(p/d)+p/d)%(p/d); //(qmul(b/d,x,p/d)+p/d)%(p/d); } LL invP(LL a,LL p){ a=(a%p+p)%p; if(a==0) return -1; LL x,y; exgcd(a,p,x,y); return (x%p+p)%p; } LL primeroot(LL P){ LL temp[1000],cnt; LL x=P-1; cnt=0; for(LL i=2;i*i<=x;i++){ if(x%i==0){ while(x%i==0){ x/=i; } temp[cnt]=i; cnt++; } } if(x>1){ temp[cnt]=x; cnt++; } for(LL g=2;g<=P-1;g++){ bool flag=1; for(int i=0;i0;T--){ LL P,n,A; scanf("%lld%lld%lld",&P,&n,&A); LL X=work(P,n,A); printf("%lld\n",X); } return 0; }