#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 map factorize(T x){ map res; for(int i=2;i*i<=x;i++){ while(x%i==0){ x/=i; res[i]++; } } if(x!=1) res[x]++; return res; } template T mod_pow(T a,long long n,T mod){ using ll = long long; T res(1); while(n){ if(n&1) res=(ll)res*a%mod; a=(ll)a*a%mod; n>>=1; } return res; } template T order(T x,T MOD){ static map> dp; vector &ps=dp[MOD]; if(ps.empty()){ auto fs=factorize(MOD-1); for(auto p:fs) ps.emplace_back(p.first); } T res=MOD-1; for(T p:ps){ while(res%p==0){ if(mod_pow(x,res/p,MOD)!=1) break; res/=p; } } return res; } //INSERT ABOVE HERE int naive(int p,int n){ vector as(p); for(int i=0;ias[j]) cnt++; return cnt&1; } signed main(){ if(0){ for(int p=2;p<20;p++){ if(!isprime(p)) continue; cout<<"P: "<>p>>n; long long o=order(n,p); cout<<(((o-1)*(p-1)/o)&1)<