-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimenos.java
More file actions
26 lines (25 loc) · 776 Bytes
/
Copy pathprimenos.java
File metadata and controls
26 lines (25 loc) · 776 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
import java.util.Arrays;
import java.util.Scanner;
public class primenos {
public static void main(String[] args) {
try (Scanner ab = new Scanner(System.in)) {
int n=ab.nextInt();
primenos ob=new primenos();
boolean[] isprime=ob.sieveoferastosthenes(n);
for (int i = 0; i <=n; i++) {
System.out.println(i+" "+isprime[i]);
}
}
}
boolean[] sieveoferastosthenes(int n){
boolean isprime[]= new boolean[n+1];
Arrays.fill(isprime,true);
isprime[0]=false;isprime[1]=false;
for (int i = 2; i*i <=n; i++) {
for (int j = 2*i; j <=n; j +=i) {
isprime[j]=false;
}
}
return isprime;
}
}