#include #include #include #include #include #include #include #include #include using namespace std; #define int long long #define endl "\n" long long power(long long x, long long n, long long mod){ long long ans = 1; while(n){ if(n&1) ans *= x; n >>= 1; x *= x; x %= mod; ans %= mod; } return ans; } bool Miller_Rabin(long long num, long long k){ if(num <= 1) return false; else if(num == 2) return true; else if(num%2 == 0) return false; long long s = 0, d = 0; random_device rnd; mt19937 mt(rnd()); // uniform_int_distribution<> rd(1,min((int)numeric_limits::max(), num-1)); for(long long n = num-1;;){ if(n%2){ d = n; break; } else s++, n >>= 1; } for(long long i = 0; i < k; i++){ // long long a = rd(mt), n = d, a2 = 1; long long a = mt()%(num-1)+1, n = d, a2 = 1; bool flag = true; a2 = power(a, d, num); if(a2 == 1) continue; for(long long r = 0, two = 1; r < s; r++, two <<= 1){ a2 = power(a, two*d, num); if(a2 == num-1){ flag = false; break; } } if(flag) return false; } return true; } signed main(){ // cin.tie(0); // ios::sync_with_stdio(false); // cout<>n; cout<<(Miller_Rabin(n, 100000)?"YES":"NO")<