# 使用Java跑出来的明明是对的，却是wa

@派大星Magic 2021-05-05 00:39 回复

# 大佬求解


import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int number;
number = scan.nextInt();
int number1;
for(int k = 0; k < number; k++) {
number1 = scan.nextInt();
if(number1 < 4) {
System.out.println(number1);
}else {
int i = 0;
for( i=2;i<=Math.sqrt(number1);i++){//为什么要到sqrt(x)呢，
//因为如果有一个大于sqrt(n)的数可以被n整除，那么必有一个数n/i也可以被n整除且小于i
if(number1%i==0) {
break;
}
}
if(i  > Math.sqrt(number1)) {
System.out.println(number1);
}

}

}
}
}

@Maxmilite  2021-05-05 06:46 回复 举报
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int number;
number = scan.nextInt();
int number1;
for(int k = 0; k < number; k++) {
number1 = scan.nextInt();
if(number1 < 4) {
// fixed here
if (number1 != 1) {
System.out.print(number1);
System.out.print(" ");
}
// fixed a println problem
// System.out.println(number1);

}else {
int i = 0;
for(i=2;i<=Math.sqrt(number1);i++){//为什么要到sqrt(x)呢，
//因为如果有一个大于sqrt(n)的数可以被n整除，那么必有一个数n/i也可以被n整除且小于i
if(number1%i==0) {
break;
}
}
if(i > Math.sqrt(number1)) {
// System.out.println(number1);
System.out.print(number1);
System.out.print(" ");
}

}

}
}
}