#include #include uint64_t reduce(__uint128_t A, uint64_t n, uint64_t ninv) { uint64_t y = (uint64_t)(A >> 64) - (uint64_t)(((__uint128_t)((uint64_t)A * ninv) * n) >> 64); return (int64_t)y < 0 ? y + n : y; } uint64_t mul(uint64_t a, uint64_t b, uint64_t n, uint64_t ninv) { return reduce((__uint128_t)a * b, n, ninv); } uint64_t powmod(uint64_t a, uint64_t k, uint64_t n, uint64_t ninv, uint64_t r) { uint64_t ret = r; while (k > 0) { if (k & 1) ret = mul(ret, a, n, ninv); a = mul(a, a, n, ninv); k >>= 1; } return ret; } int is_prime(uint64_t n) { if (n < 2) return 0; if (n < 4) return 1; if (n & 1 == 0) return 0; static uint64_t base[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; int s = __builtin_ctzll(n - 1); uint64_t d = (n - 1) >> s; uint64_t r = (uint64_t)-1ull % n + 1; uint64_t r2 = (__uint128_t)(__int128_t)-1 % n + 1; uint64_t ninv = n; for (int _ = 0; _ < 5; ++_) ninv *= 2 - ninv * n; for (int i = 0; i < 12; ++i) { uint64_t a = reduce((__uint128_t)r2 * base[i], n, ninv); if (a >= n) break; uint64_t c = powmod(a, d, n, ninv, r); if (c == r) continue; int f = 0; for (int q = 0; q < s && f == 0; q++) { f |= (c == (n - r)); c = mul(c, c, n, ninv); } if (f == 0) return 0; } return 1; } uint64_t in(void) { uint64_t 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; } void out(uint64_t x) { if (x >= 10) out((((__uint128_t)x * 14757395258967641293ull) >> 3) >> 64); putchar_unlocked(x - ((((__uint128_t)x * 14757395258967641293ull) >> 3) >> 64) * 10 + 48); } int main(void) { uint64_t Q = in(); while (Q--) { uint64_t x = in(); out(x); putchar_unlocked(' '); out(is_prime(x)); putchar_unlocked('\n'); } return 0; }