import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static int n;
static int[] nums;
static ArrayList<Integer> arrayList=new ArrayList<>();
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
n= scanner.nextInt();
nums=new int[n+1];
for (int i = 2; i <= n; i++) {
if (nums[i]==0){
arrayList.add(i);
}
for (int j = 0; j <arrayList.size() ; j++) {
if (arrayList.get(j)*i>n)continue;
nums[arrayList.get(j)*i]=1;
}
}
for (int i = 1; i <= n ; i++) {
if (nums[i]==1)continue;
System.out.println(i);
}
scanner.close();
}
}
JAVA线性筛素数
最新推荐文章于 2024-11-13 17:07:29 发布