2~n的素数
public class Test{
public static void PrimeNum(int n) {
int[] num = new int[n];
for (int i = 1; i < n; i++) {
num[i] = 1;
}
for (int i = 2; i <= n; i++) {
if (num[i - 1] == 1)
System.out.print(i + " ");
for (int j = 2 * i; j <= n; j += i) {
num[j - 1] = 0;
}
}
}
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
PrimeNum(sc.nextInt());
}
}