#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#define ENVIRONMENT_LINKED_ACL #ifdef ENVIRONMENT_LINKED_ACL #include #include #include #endif //#define ENVIRONMENT_LINKED_BOOST #ifdef ENVIRONMENT_LINKED_BOOST #include #include #endif using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; #define REP(i, a, b) for (ll i = a; i < b; ++i) #define REPREV(i, a, b) for (ll i = a; i > b; --i) const int _ = []() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(10); return 0; }(); template void resize(value_t& v, const value_t&& val) { v = val; } template void resize(std::vector& v, const value_t&& val, int size, arg_t... arg) { v.resize(size); for (auto& c : v) resize(c, std::forward(val), arg...); } template void chmin(A& a, const B& b) { a = min(a, static_cast(b)); }; template void chmax(A& a, const B& b) { a = max(a, static_cast(b)); }; template T modpow(T r, T n, T mod) { T ans = 1; T tmp = r % mod; while (n > 0) { if ((n & 1) > 0) { ans = ans * tmp % mod; } tmp = tmp * tmp % mod; n >>= 1; } return ans; } //素数判定O(logn) bool is_prime(unsigned int n) { if (n == 1 || n % 2 == 0) return n == 2; unsigned int d = n - 1, s = 0; while (d % 2 == 0) { d /= 2; ++s; } constexpr std::array test = {2, 7, 61}; for (auto a : test) { if (n <= a) break; unsigned long long tmp = modpow(a, d, n); if (tmp == 1) continue; bool no_prime = true; for (int r = 0; r < s; ++r) { if (tmp == n - 1) { no_prime = false; break; } tmp = tmp * tmp % n; } if (no_prime) return false; } return true; } bool is_prime_ull(unsigned long long n) { if (n == 1 || n % 2 == 0) return n == 2; unsigned long long d = n - 1, s = 0; while (d % 2 == 0) { d /= 2; ++s; } constexpr std::array test = {2, 325, 9375, 28178, 450775, 9780504, 1795265022ULL}; for (auto a : test) { if (n <= a) break; __uint128_t tmp = modpow<__uint128_t>(a, d, n); if (tmp == 1) continue; bool no_prime = true; for (int r = 0; r < s; ++r) { if (tmp == n - 1) { no_prime = false; break; } tmp = tmp * tmp % n; } if (no_prime) return false; } return true; } int main() { ll n; cin >> n; REP(i, 0, n) { ull x; cin >> x; cout << x << " " << (is_prime_ull(x) ? 1 : 0) << endl; } return 0; }