import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } // a b (mod m) ulong multiply(ulong a, ulong b, ulong m) in { assert(m < 1UL << 63, "multiply: m < 2^63 must hold"); assert(a < m, "multiply: a < m must hold"); assert(b < m, "multiply: b < m must hold"); } do { ulong c = 0; for (; a; a >>= 1) { if (a & 1) { c += b; if (c >= m) c -= m; } b <<= 1; if (b >= m) b -= m; } return c; } // a^e (mod m) ulong power(ulong a, ulong e, ulong m) in { assert(m < 1UL << 63, "power: m < 2^63 must hold"); assert(a < m, "power: a < m must hold"); } do { long b = 1; for (; e; e >>= 1) { if (e & 1) b = multiply(b, a, m); a = multiply(a, a, m); } return b; } // Checks if n is a prime using Miller-Rabin test bool isPrime(ulong n) in { assert(n < 1UL << 63, "isPrime: n < 2^63 must hold"); } do { import std.stdio; import core.bitop : bsf; // http://miller-rabin.appspot.com/ enum ulong[] BASES = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]; if (n <= 1 || !(n & 1)) return (n == 2); const s = bsf(n - 1); const d = (n - 1) >> s; foreach (base; BASES) { ulong a = base % n; if (a == 0) continue; a = power(a, d, n); if (a == 1 || a == n - 1) continue; bool ok = false; foreach (_; 0 .. s - 1) { a = multiply(a, a, n); if (a == n - 1) { ok = true; break; } } if (!ok) return false; } return true; } int N; long[] X; void main() { try { for (; ; ) { N = readInt(); X = new long[N]; foreach (i; 0 .. N) { X[i] = readLong(); } foreach (i; 0 .. N) { writeln(X[i], " ", isPrime(X[i]) ? 1 : 0); } } } catch (EOFException e) { } }