-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo_4948.java
More file actions
39 lines (37 loc) · 749 Bytes
/
Copy pathNo_4948.java
File metadata and controls
39 lines (37 loc) · 749 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
38
39
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class No_4948 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> newArray = new ArrayList<Integer>();
while (true) {
int num = sc.nextInt();
if (num == 0) {
break;
}
int count = 0;
for (int i = num+1; i <= num * 2; i++) {
if (isPrime(i)) {
count++;
}
}
newArray.add(count);
}
for(int j = 0; j < newArray.size(); j++) {
System.out.println(newArray.get(j));
}
sc.close();
}
private static boolean isPrime(int num) {
if (num <= 1) {
return false;
}
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
}