-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI007.java
More file actions
37 lines (35 loc) · 963 Bytes
/
I007.java
File metadata and controls
37 lines (35 loc) · 963 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
33
34
35
36
37
package levelB;
import java.util.ArrayList;
import java.util.Scanner;
public class I007 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt();
ArrayList<Integer> list=new ArrayList<>();
list.add(2);
list.add(3);
for(int i=4;i<=N;i++){
boolean flag=true;
for(int j=2;j<=Math.sqrt(i);j++){
if(i%j==0){
flag=false;
break;
}
}
if(flag){
list.add(i);
}
}
int pnums[]=new int[list.size()];
for(int i=0;i<pnums.length;i++){
pnums[i]=list.get(i);
}
int count=0;
for(int i=0;i<pnums.length-1;i++){
if(pnums[i+1]-pnums[i]==2){
count++;
}
}
System.out.print(count);
}
}