#include #include #define INF 1000000000LL using namespace std; typedef long long ll; typedef pair P; std::random_device rd; std::mt19937 mt(rd()); ll mod_pow(ll x,ll n,ll mod){ ll res=1; while(n>0){ if(n&1LL)res=res*x%mod; x=x*x%mod; n>>=1; } return res; } ll calc(ll v,ll tgt,int po){ ll ans=1; for(int i=0;itgt)return false; } if(anstgt)return false; return true; } bool is_prime(ll val){ if(val==1LL)return false; if(val==2LL)return true; for(int i=0;i<5;i++){ ll v=rd()%val; if(v==0LL)v=1; if(mod_pow(v,val-1LL,val)!=1LL)return false; } return true; } bool C(ll v,ll tgt,int po){ ll res=1; while(po>0){ if(po&1){ if(log(tgt)+1<(log(res)+log(v)))return false; res*=v; } if(po>1 && log(tgt)+1<(log(v)+log(v)))return false; v*=v; po>>=1; } return res<=tgt; } bool check(ll val,int po){ if(po==1)return is_prime(val); else{ ll l=2,r=min(INF,val); if(!C(l,val,po))return false; while(l+1