Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
for (int i = 0; i < n; i++)
{
int x = cin.nextInt();
boolean isPrime = true;
for (int j = 2; j * j <= x; j ++)
{
if (x % j == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
System.out.println (x + " is prime");
else
System.out.println (x + " is not prime");
}
}
}