import java.util.ArrayList;
import java.util.List;
public class A2513220238_ex2_p_1 {
// 判断一个数是否是素数
public static boolean isPrime(int num) {
if (num <= 1) {
return false;
}
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
// 找到[2, N]范围内的所有素数
public static List<Integer> findPrimes(int N) {
List<Integer> primes = new ArrayList<>();
for (int i = 2; i <= N; i++) {
if (isPrime(i)) {
primes.add(i);
}
}
return primes;
}
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java PrimeNumbers N");
return;
}
int N = Integer.parseInt(args[0]);
if (N < 2) {
System.out.println("N must be greater than or equal to 2.");
return;
}
List<Integer> primeNumbers = findPrimes(N);
System.out.println("Prime numbers between 2 and " + N + ":");
for (int prime : primeNumbers) {
System.out.print(prime + " ");
}
}
}