def is_prime(n: int) -> bool: # ミラー–ラビン素数判定法 # https://qiita.com/srtk86/items/609737d50c9ef5f5dc59 # https://en.wikipedia.org/wiki/Strong_pseudoprime assert isinstance(n, int) and 0 < n if n == 2: return True if n == 1 or n & 1 == 0: return False d = (n - 1) >> 1 while d & 1 == 0: d >>= 1 # n-1=(2**s)*d (dは奇数) L = [a for a in (2, 325, 9375, 28178, 450775, 9780504, 1795265022) if a < n] if n >= 2**64: # これはwikiによる from random import randint # これだけあればまず誤判定しない L += [randint(1, n-1) for _ in range(20)] for a in L: # nが素数ならばa^d≡1 (mod p) もしくは t = d # a^((2^r)*d)≡-1 (mod p) が成立すべき y = pow(a, t, n) while t != n - 1 and y != 1 and y != n - 1: y = (y * y) % n t <<= 1 if y != n - 1 and t & 1 == 0: return False else: return True n = int(input()) for _ in range(n): x = int(input()) print(x, int(is_prime(x)))