//#define TEST #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int M=1e7+10; bool is_p[M]; int prime[M], primelen; int euler(int N) { int len = 0; memset(is_p, true, sizeof(is_p)); for(int i = 2; i < N; i++) { if(is_p[i]) { prime[len] = i; len++; } for(int j = 0; j < len && prime[j] <= i; j++) { if(i * prime[j] >= N) break; is_p[i * prime[j]] = false; if(i % prime[j] == 0) break; } } return len; } LL qmul(LL a,LL b,LL mod){ return (LL)((__int128_t)a*b%mod); /* LL ans=0; 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=qmul(ans,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 a; } LL exgcd(LL a,LL b,LL &x,LL &y){ if(b == 0){ x = 1, y = 0; return b; } 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){ a=(a%p+p)%p;b=(b%p+p)%p; LL x,y; LL d=exgcd(a,p,x,y); if(b%d!=0) return -1; return (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; } int factorlist(LL x,LL z,LL* p,int* k){ int cnt=0; LL y=gcd(z/x,x); LL cap=pow(z,0.25)+1; for(int i=0;prime[i]<=cap;i++){ if(y%prime[i]!=0) continue; cnt++; p[cnt]=prime[i]; while(y%prime[i]==0){ y/=prime[i]; } } if(y>1){ cnt++; p[cnt]=y; } for(int i=1;i<=cnt;i++){ k[i]=0; while(x%p[i]==0){ x/=p[i]; k[i]++; } } p[0]=x; return cnt; } const LL hashmod=1000003; LL phash[hashmod*2]; LL f_origin[hashmod*2]; void makehash(LL Bps,LL p,LL P){ memset(phash,-1,sizeof(phash)); memset(f_origin,-1,sizeof(f_origin)); LL f=1; phash[f%hashmod]=0; f_origin[f%hashmod]=f; for(LL r=1;r0;T--){ LL P,n,A,X; scanf("%lld%lld%lld",&P,&n,&A); X=work(P,n,A); printf("%lld\n",X); } return 0; }