module mdl contains function mul_mod(a,b,m)result(ret) implicit none integer(8),value::a,b,m integer(8)::ret,tmp a=mod(a,m) b=mod(b,m) ret=0 do while(b>1) if(mod(b,2)==0)then tmp=a if(tmp>=m-a)tmp=tmp-m a=mod(a+tmp,m) b=b/2 else if(ret>=m-a)ret=ret-m ret=mod(ret+a,m) b=b-1 end if end do if(ret>=m-a)ret=ret-m ret=mod(ret+a,m) end function integer(8) function pow(a,n,p) implicit none integer(8),value::a,n,p a=mod(a,p) pow=1 do while(n>0) if(mod(n,2)==1)pow=mul_mod(pow,a,p) n=n/2 a=mul_mod(a,a,p) end do end function logical function isPrime(a) integer(8)::i,j,k,x,tmp integer(8),value::a logical::flag isPrime=.true. do i=12,min(a-1,20) tmp=pow(i,a-1,a) isPrime=isPrime.and.tmp==1 if(.not.isPrime)return end do if(a<10000)then do i=2,a if(i*i>=a)exit isPrime=isPrime.and.mod(a,i)/=0 if(isPrime)return end do end if end function end module program main use mdl implicit none integer::n integer(8)::i,j,k integer(8),allocatable::x(:) read*,n allocate(x(n)) do i=1,n read*,x(i) if(isPrime(x(i)))then print*,x(i),1 else print*,x(i),0 end if end do end program