#line 1 "test/yuki/No-3030.test.cpp" #define PROBLEM "https://yukicoder.me/problems/no/3030" #line 2 "template.hpp" #include using namespace std; #define rep(i, N) for(int i=0;i<(N);i++) #define all(x) (x).begin(),(x).end() #define popcount(x) __builtin_popcount(x) using i128=__int128_t; using ll = long long; using ld = long double; using graph = vector>; using P = pair; constexpr int inf = 1e9; constexpr ll infl = 1e18; constexpr ld eps = 1e-6; const long double pi = acos(-1); constexpr uint64_t MOD = 1e9 + 7; constexpr uint64_t MOD2 = 998244353; constexpr int dx[] = { 1,0,-1,0 }; constexpr int dy[] = { 0,1,0,-1 }; templatestatic constexpr inline void chmax(T&x,T y){if(xstatic constexpr inline void chmin(T&x,T y){if(x>y)x=y;} #line 2 "math/mod_pow.hpp" template constexpr inline U mod_pow(T base, T exp, T mod){ T ans = 1; base %= mod; while (exp > 0) { if (exp & 1) { ans *= base; ans %= mod; } base *= base; base %= mod; exp >>= 1; } return ans; } ///@brief mod pow(バイナリ法) #line 3 "math/miller.hpp" namespace prime { namespace miller { using i128 = __int128_t; using u128 = __uint128_t; using u64 = uint64_t; using u32 = uint32_t; constexpr bool inline miller_rabin(u64 n, const u64 bases[], int length) { u64 d = n - 1; while (~d & 1) { d >>= 1; } u64 rev = n - 1; for (int i = 0; i < length; i++) { u64 a = bases[i]; if (n <= a) { return true; } u64 t = d; u128 y = mod_pow(a, t, n); while (t != n - 1 && y != 1 && y != rev) { (y *= y) %= n; t <<= 1; } if (y != rev && (~t & 1))return false; } return true; } constexpr u64 bases_int[3] = { 2, 7, 61 }; // intだと、2,7,61で十分 constexpr u64 bases_ll[7] = { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 }; constexpr bool inline is_prime(u64 n) { if (n < 2) { return false; } else if (n == 2) { return true; } else if (~n & 1) { return false; } if (n < (1ul << 31)) { return miller_rabin(n, bases_int, 3); } else { return miller_rabin(n, bases_ll, 7); } } }; }; ///@brief MillerRabinの素数判定 #line 4 "test/yuki/No-3030.test.cpp" int main(){ int n; scanf("%d", &n); for (int i = 0; i < n; i++){ uint64_t xi; scanf("%lld", &xi); printf("%lld ", xi); if (prime::miller::is_prime(xi)) { puts("1"); } else { puts("0"); } } }