#line 1 "/home/anqooqie/.proconlib/tools/util.hpp" #ifdef LOCAL #ifndef _GLIBCXX_DEBUG #define _GLIBCXX_DEBUG #endif #else #ifndef NDEBUG #define NDEBUG #endif #endif #include using i64 = ::std::int_fast64_t; using u64 = ::std::uint_fast64_t; using i32 = ::std::int_fast32_t; using u32 = ::std::uint_fast32_t; #define ALL(x) ::std::begin((x)), ::std::end((x)) namespace tools { namespace detail { namespace util { template class is_range { private: template static auto check(U x) -> decltype(::std::begin(x), ::std::end(x), ::std::true_type{}); static ::std::false_type check(...); public: static const bool value = decltype(check(::std::declval()))::value; }; template class has_val { private: template static auto check(U x) -> decltype(x.val(), ::std::true_type{}); static ::std::false_type check(...); public: static const bool value = decltype(check(::std::declval()))::value; }; template ::std::istream& read(::std::istream& is, T& container) { for (auto& v : container) { is >> v; } return is; } template ::std::ostream& debug_print(::std::ostream& os, const T& container) { ::std::string delimiter = ""; os << '['; for (const auto& v : container) { os << delimiter << v; delimiter = ", "; } os << ']'; return os; } } } template void resize(::std::vector& vector, const Head& head) { vector.resize(head); } template void resize(::std::vector& vector, const Head& head, const Tail&... tail) { vector.resize(head); for (auto& child : vector) { ::tools::resize(child, tail...); } } template auto fill(::std::vector& vector, const V& value) -> ::std::enable_if_t::value, void> { ::std::fill(::std::begin(vector), ::std::end(vector), value); } template auto fill(::std::vector& vector, const V& value) -> ::std::enable_if_t<::tools::detail::util::is_range::value, void> { for (auto& child : vector) { ::tools::fill(child, value); } } } template ::std::istream& operator>>(::std::istream& is, ::std::vector& vector) { return ::tools::detail::util::read(is, vector); } template ::std::istream& operator>>(::std::istream& is, ::std::array& array) { return ::tools::detail::util::read(is, array); } template ::std::ostream& operator<<(::std::ostream& os, const ::std::vector& vector) { return ::tools::detail::util::debug_print(os, vector); } template ::std::ostream& operator<<(::std::ostream& os, const ::std::array& array) { return ::tools::detail::util::debug_print(os, array); } template ::std::ostream& operator<<(::std::ostream& os, const ::std::unordered_set& unordered_set) { return ::tools::detail::util::debug_print(os, unordered_set); } template ::std::ostream& operator<<(::std::ostream& os, ::std::stack& stack) { ::std::stack other; std::string delimiter = ""; os << '['; while (!stack.empty()) { os << delimiter << stack.top(); delimiter = ", "; other.push(stack.top()); stack.pop(); } os << ']'; while (!other.empty()) { stack.push(other.top()); other.pop(); } return os; } template ::std::ostream& operator<<(::std::ostream& os, const ::std::pair& pair) { return os << '[' << pair.first << ", " << pair.second << ']'; } template ::std::ostream& operator<<(::std::ostream& os, const ::std::tuple& tuple) { if constexpr (I == -1) { os << '['; } else if constexpr (I == int(sizeof...(Args))) { os << ']'; } else if constexpr (I == 0) { os << ::std::get(tuple); } else { os << ", " << ::std::get(tuple); } if constexpr (I < int(sizeof...(Args))) { return operator<<(os, tuple); } else { return os; } } template auto operator<<(::std::ostream& os, const T& x) -> ::std::enable_if_t<::tools::detail::util::has_val::value, ::std::ostream&> { return os << x.val(); } #line 2 "main.cpp" constexpr ::std::uint_fast64_t prod_mod(const ::std::uint_fast64_t x, const ::std::uint_fast64_t y, const ::std::uint_fast64_t m) { using u128 = unsigned __int128; return ::std::uint_fast64_t((u128(x) * u128(y)) % u128(m)); } constexpr ::std::uint_fast64_t pow_mod(const ::std::uint_fast64_t x, ::std::uint_fast64_t n, const ::std::uint_fast64_t m) { if (m == 1) return 0; ::std::uint_fast64_t r = 1; ::std::uint_fast64_t y = x % m; while (n > 0) { if ((n & 1) > 0) { r = prod_mod(r, y, m); } y = prod_mod(y, y, m); n /= 2; } return r; } constexpr bool is_prime(const ::std::uint_fast64_t n) { constexpr ::std::array<::std::uint_fast64_t, 7> bases = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; ::std::uint_fast64_t d = n - 1; for (; d % 2 == 0; d /= 2); for (const ::std::uint_fast64_t a : bases) { if (a % n == 0) return true; ::std::uint_fast64_t power = d; ::std::uint_fast64_t target = pow_mod(a, power, n); bool is_composite = true; if (target == 1) is_composite = false; for (; is_composite && power != n - 1; power *= 2, target = prod_mod(target, target, n)) { if (target == n - 1) is_composite = false; } if (is_composite) { return false; } } return true; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); i64 n; std::cin >> n; std::vector x(n); std::cin >> x; for (const i64& x_i : x) { std::cout << x_i << ' ' << (is_prime(x_i) ? 1 : 0) << '\n'; } return 0; }