-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSieve.java
More file actions
32 lines (27 loc) · 717 Bytes
/
Sieve.java
File metadata and controls
32 lines (27 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
public class Sieve {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
boolean A[]=new boolean[n];
for(int x=0;x<n;x++){
A[x]=true;
}
for(int x=2;x<n;x++){ //use Math.sqrt() for better performance
if(A[x]==true){
System.out.print(x+" ");
for(int y=x;y<n;y+=x){
A[y]=false;
}
}
}
}
// public boolean Sieve(int a){
// for(){
// if(a%x==0){
// return false;
// }
// }
// return true;
// }
}