#include #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; random_device seed_gen; mt19937 rng(seed_gen()); lint modpow(lint a,lint k,lint m){ lint r=1%m; for(lint x=a%m;k>0;k>>=1,x=__int128(x)*x%m) if(k&1) r=__int128(r)*x%m; return r; } bool Miller_Rabin(lint n,int k=20){ if(n<=1) return false; if(n%2==0) return n==2; int s=0; lint d=n-1; while(~d&1) s++, d>>=1; while(k--){ lint a=rng()%(n-3)+2; lint x=modpow(a,d,n); if(x==1 || x==n-1) continue; bool b=false; for(int r=1;r