import java.util.Scanner; /** * @date 2020/3/4 - 下午 10:40 */ public class 筛法求素数 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[n+1]; for (int i = 2; i <=n; i++) { if (a[i]==0){ System.out.println(i); for (int j = 2; j*i<=n; j++) {//把索引是i的倍数都标记出来 a[i*j]=1; } } } } }