-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_4948.java
More file actions
57 lines (54 loc) · 1.11 KB
/
_4948.java
File metadata and controls
57 lines (54 loc) · 1.11 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package backjoon;
// https://www.acmicpc.net/problem/4948
// 베르트랑 공준
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _4948 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//sol memory 24172 runtime 164
int cnt = 0;
while(true){
int N = Integer.parseInt(br.readLine());
if(N == 0) break;
boolean[] isNotPrime = new boolean[N*2+1]; //기본값이 false
isNotPrime[0] = isNotPrime[1] = true;
for (int i = 2; i <= Math.sqrt(isNotPrime.length); i++) {
if (isNotPrime[i]) {
continue;
}
for (int j = i * i; j < isNotPrime.length; j += i) {
isNotPrime[j] = true;
}
}
//N보다 크고 2N보다 작거나 같기때문에 N+1을 해준다.
for (int i = N+1; i <= N*2; i++) {
if (!isNotPrime[i]) {
cnt++;
}
}
System.out.println(cnt);
cnt = 0;
}
}
}
/*
input
1
10
13
100
1000
10000
100000
0
output
1
4
3
21
135
1033
8392
*/