#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma region header #include #include #include #include #include #include #include #pragma endregion header #pragma region type template using V = std::vector; using i8 = std::int8_t; using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using i128 = __int128_t; using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using u128 = __uint128_t; using f32 = float; using f64 = double; using f80 = long double; #pragma endregion type #pragma region io template Int read_int(void) { Int c, x = 0, f = 1; while (c = getchar_unlocked(), c < 48 || c > 57) if (c == 45) f = -f; while (47 < c && c < 58) { x = x * 10 + c - 48; c = getchar_unlocked(); } return f * x; } template void write_int(Int x) { if (x < 0) { putchar_unlocked('-'); x = -x; } if (x >= 10) write_int(x / 10); putchar_unlocked(x - x / 10 * 10 + 48); } template Unsigned read_uint(void) { Unsigned c, x = 0; while (c = getchar_unlocked(), c < 48 || c > 57); while (47 < c && c < 58) { x = x * 10 + c - 48; c = getchar_unlocked(); } return x; } template void write_uint(Unsigned x) { if (x >= 10) write_uint(x / 10); putchar_unlocked(x - x / 10 * 10 + 48); } void NL() { putchar_unlocked('\n'); } void SP() { putchar_unlocked(' '); } #pragma endregion io #pragma region binary_gcd template T bin_gcd(T a, T b) { if (!a || !b) return a | b; T shift = __builtin_ctzll(a | b); a >>= __builtin_ctzll(a); do { b >>= __builtin_ctzll(b); if (a > b) { T t = a; a = b; b = t; } b -= a; } while (b); return a << shift; } #pragma endregion binary_gcd #pragma region dynamic montgomery modint template struct RuntimeModInt { static Word mod, inv, r2; Word x; RuntimeModInt() : x(0) {} RuntimeModInt(Word _x) : x(init(_x)) {} bool operator==(const RuntimeModInt &rhs) const { return x == rhs.x; } bool operator!=(const RuntimeModInt &rhs) const { return x != rhs.x; } RuntimeModInt operator-() const { return RuntimeModInt() - RuntimeModInt(*this); } RuntimeModInt &operator+=(const RuntimeModInt &rhs) { if (Int(x += rhs.x - 2 * mod) < 0) x += 2 * mod; return *this; } RuntimeModInt &operator-=(const RuntimeModInt &rhs) { if (Int(x -= rhs.x) < 0) x += 2 * mod; return *this; } RuntimeModInt &operator*=(const RuntimeModInt &rhs) { x = reduce(DWord(x) * rhs.x); return *this; } RuntimeModInt &operator/=(const RuntimeModInt &rhs) { *this *= rhs.inverse(); return *this; } RuntimeModInt operator+(const RuntimeModInt &rhs) const { return ModInt(*this) += rhs; } RuntimeModInt operator-(const RuntimeModInt &rhs) const { return RuntimeModInt(*this) -= rhs; } RuntimeModInt operator*(const RuntimeModInt &rhs) const { return RuntimeModInt(*this) *= rhs; } RuntimeModInt operator/(const RuntimeModInt &rhs) const { return RuntimeModInt(*this) /= rhs; } RuntimeModInt pow(u64 e) const { RuntimeModInt ret{1}; for (RuntimeModInt base = *this; e; e >>= 1, base *= base) { if (e & 1) ret *= base; } return ret; } RuntimeModInt inverse() const { return pow(mod - 2); } Word get() const { return reduce(x); } static constexpr int word_bits = sizeof(Word) * 8; static Word get_mod() { return mod; } static Word get_r(Word m) { Word ret = m; for (i64 i = 0; i < 5; ++i) ret *= 2 - m * ret; return ret; } static Word get_inv() { return -DWord(mod) % mod; } static Word init(Word w) { return reduce(DWord(w) * r2); } static void set_mod(Word m) { mod = m; inv = get_r(mod); r2 = -DWord(mod) % mod; } static Word reduce(DWord x) { Word y = Word(x >> word_bits) - Word((DWord(Word(x) * inv) * mod) >> word_bits); return Int(y) < 0 ? y + mod : y; } }; using m64 = RuntimeModInt; template<> u64 m64::mod = 0; template<> u64 m64::inv = 0; template<> u64 m64::r2 = 0; using m32 = RuntimeModInt; template<> u32 m32::mod = 0; template<> u32 m32::inv = 0; template<> u32 m32::r2 = 0; #pragma endregion dynamic montgomery modint #pragma region Miller_Rabin primary test template bool miller_rabin(Unsigned N, const V& bases) { mint::set_mod(N); Unsigned M = N - 1; int s = __builtin_ctzll(N - 1); Unsigned d = (N - 1) >> s; mint one{1}, rev{N - 1}; for (const auto& base : bases) { if (N <= base) break; u64 t = d; mint y = mint(base).pow(t); while (t != M && y != one && y != rev) { y *= y; t <<= 1; } if (y != rev && (!(t & 1))) return false; } return true; } bool is_prime(u64 N) { if (N <= 3ul) return N == 2ul || N == 3ul; if (!(N & 1)) return false; if (N < (1u << 31)) return miller_rabin(u32(N), {2u, 7u, 61u}); return miller_rabin(N, {2u, 325u, 9375u, 28178u, 450775u, 9780504u, 1795265022u}); } #pragma endregion Miller_Rabin primary test int main() { int T; scanf("%d", &T); while (T--) { u64 N; scanf("%llu", &N); printf("%llu %d\n", N, is_prime(N)); } }