import strutils const Mod : int = 1000000007 proc powMod*(n : int, x : int, m = Mod) : int = if x == 0: return 1 if n == 1: return 1 if x == 1: return (n mod m) if x mod 2 == 0: return powMod((n * n) mod m, x div 2, m) mod m else: return n * powMod((n * n) mod m, x div 2, m) mod m proc mr_check(n,d,s,p:int) : bool = var x = powMod(p,d,n) if x == 1: return false for i in 0 ..< s: if x == n - 1 : return false x = x * x mod n return true proc miller_rabin*(n : Natural) : bool = if n <= 1 : return false var s = 0 d = n - 1 while d mod 2 == 0: s += 1 d = d shr 1 let bases = [2,3,5,7,11,13,17,263,1321,30983,500911,9780517,1795265047] for p in bases: if p == n: return true if mr_check(n, d, s, p): return false return true var n = stdin.readLine.parseInt for i in 0 ..< n : var z = stdin.readLine.parseInt var ib : bool = miller_rabin(z) echo ($i & " " & $int(ib))