#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; class Xorshift { private: unsigned x, y, z, w; public: Xorshift(unsigned seed=88675123, int loop=50){ x = 123456789; y = 362436069; z = 521288629; w = seed; while(--loop >= 0){ (*this)(); } } unsigned operator()(){ unsigned t=(x^(x<<11)); x=y; y=z; z=w; return w=(w^(w>>19))^(t^(t>>8)); } unsigned operator()(unsigned size){ return (*this)() % size; } unsigned long long get64(){ unsigned long long a = (*this)(); unsigned long long b = (*this)(); return (a << 32) | b; } unsigned long long get64(unsigned long long size){ return get64() % size; } template void shufflte(vector& v){ unsigned n = v.size(); for(unsigned i=0; i=0; --i){ ret *= 2; if(a & (1LL << i)) ret += b; ret %= mod; } return ret; } long long modpow(long long a, long long b, long long mod) { long long ret = 1; long long tmp = a; while(b > 0){ if(b & 1) ret = modmul(ret, tmp, mod); tmp = modmul(tmp, tmp, mod); b >>= 1; } return ret; } bool millerRabinPrimalityTest(long long n, int loop=10) { if(n < 2) return false; long long d = n - 1; int s = 0; while(d % 2 == 0){ ++ s; d /= 2; } while(--loop >= 0){ long long a = xorshift.get64(n-1) + 1; long long x = modpow(a, d, n); if(x != 1){ bool isComposite = true; for(int r=0; r> n; while(--n >= 0){ long long x; cin >> x; int ans = millerRabinPrimalityTest(x) ? 1 : 0; cout << x << ' ' << ans << endl; } return 0; }