#include #include #include #include #include #include #include #include using namespace std; bool miller_rabin(unsigned long long n) { if (n <= 1) return false; if (n == 2) return true; static mt19937 mt(time(NULL)); using u64 = unsigned long long; using u128 = __uint128_t; u64 s = n - 1; int e = 0; for (; s % 2 == 0; s /= 2) e++; auto mul = [&](u64 a, u64 b, u64 m) { return u128(a) * b % m; }; for (int ii = 0; ii < 8; ii++) { u64 x = std::uniform_int_distribution(2, n - 1)(mt); u64 r = 1; for (u64 i = s; i > 0; i >>= 1, x = mul(x, x, n)) { if (i & 1) r = mul(r, x, n); } if (r == 1) continue; for (int i = 1; i < e && r != n - 1; i++) { r = mul(r, r, n); } if (r != n - 1) return false; } return true; } int main() { int n; cin >> n; while (n--) { long long x; scanf("%lld", &x); printf("%lld %d\n", x, miller_rabin(x)); } }