#include using namespace std; //g++ temp.cpp -DLOCAL でコンパイルする struct Miller_Rabin { unsigned long long mul_mod(unsigned long long a, unsigned long long b, unsigned long long m) { unsigned long long ans = 0; #ifdef LOCAL if(a > b) std::swap(a, b); while(b){ if(b & 1){ ans += a; if(ans >= m) ans -= m; } if((a <<= 1) >= m) a -= m; b >>= 1; } #else ans = (unsigned long long)((__int128)(a) * b % m); #endif return ans; } unsigned long long pow_mod(unsigned long long x, unsigned long long n, unsigned long long m) { if (m == 1) return 0; unsigned long long _m = (unsigned long long)(m); unsigned long long r = 1; unsigned long long y = x < 0 ? x % m + m : x % m; while (n) { if (n & 1) r = mul_mod(r, y, _m); y = mul_mod(y, y, _m); n >>= 1; } return r; } bool is_prime(unsigned long long n) { if (n <= 1) return false; if (n == 2 || n == 3 || n == 5) return true; if (n % 2 == 0) return false; unsigned long long d = n - 1; while (d % 2 == 0) d /= 2; constexpr long long bases[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; for (long long a : bases) { unsigned long long t = d; unsigned long long y = pow_mod(a, t, n); while (t != n - 1 && y != 1 && y != n - 1) { y = y * y % n; t <<= 1; } if (y != n - 1 && t % 2 == 0) return false; } return true; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); Miller_Rabin MR; int T; cin >> T; while(T--){ unsigned long long v; cin >> v; cout << v << ' ' << MR.is_prime(v) << '\n'; } }