#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair P; ll powmod(__int128_t a, ll k, ll m){ __int128_t ap=a, ans=1; while(k){ if(k&1){ ans*=ap; ans%=m; } k>>=1; ap=ap*ap%m; } return ans; } random_device rnd; mt19937_64 mt(rnd()); bool is_prime(ll n){ if(n<=1) return false; if(n==2) return true; if(!(n&1)) return false; ll d=n-1; int k=0; while(!(d&1)){ d>>=1; k++; } uniform_int_distribution rndn(2, n-1); for(int i=0; i<10; i++){ ll a=rndn(mt); bool comp=1; ll ap=powmod(a, d, n); if(ap==1 || ap==n-1) continue; for(int r=1; r>n; ll a[9]; for(int i=0; i>a[i]; vector v; while(1){ ll p10=1, p=0; for(int i=0; i=10) p10*=100; else p10*=10; } v.push_back(p); if(!next_permutation(a, a+n)) break; } sort(v.begin(), v.end(), greater()); for(int i=0; i