1 package test ;
2 import java.util.Scanner ;
3 public class hello
4 {
5 public static void main(String [] args)
6 {
7 Scanner read = new Scanner(System.in);
8 while(read.hasNext())
9 {
10 String rr = read.next();
11 int maxn=Integer.parseInt(rr);
12 boolean isprime[] = new boolean [maxn] ; //Java 默认初始化值为false
13 // int prime[] =new int [maxn/3];
14 int i,j;
15 for( i=2 ; i<maxn ; i++ )
16 {
17 if(!isprime[i])
18 {
19 for(j=i+i ;j<maxn ;j+=i)
20 isprime[j]=true;
21 }
22 }
23 for(i=2 ;i<maxn ;i++)
24 {
25 if(!isprime[i])
26 System.out.print(" "+i);
27 }
28 System.out.println();
29 }
30 }
31 }
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有