#Miller-Rabinの素数判定法 def Miller_Rabin_Primality_Test(N,Times=20): """Miller-Rabinによる整数Nの素数判定を行う. N:整数 ※:Trueは正確にはProbably Trueである(Falseは確定False). """ from random import randint as ri if N==2: return True if N==1 or N&1==0: return False q=N-1 k=0 while q&1==0: k+=1 q>>=1 for _ in range(Times): m=ri(2,N-1) y=pow(m,q,N) if y==1: return True for i in range(k): if (y+1)%N==0: return True y*=y y%=N return False #================================================ N=int(input()) Y=[0]*N for i in range(N): x=int(input()) if Miller_Rabin_Primality_Test(x,30): Y[i]="{} {}".format(x,1) else: Y[i]="{} {}".format(x,0) print("\n".join(map(str,Y)))