-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1929.java
More file actions
34 lines (29 loc) · 715 Bytes
/
Copy path1929.java
File metadata and controls
34 lines (29 loc) · 715 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
// 1929. 소수 구하기
// 2019.08.21
// 수학
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
int m = Integer.parseInt(s[0]);
int n = Integer.parseInt(s[1]);
// 에라토스테네스의 체
Boolean prime[] = new Boolean[n + 1];
Arrays.fill(prime, true);
prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (prime[i]) {
for (int j = i * i; j <= n; j += i) {
prime[j] = false;
}
}
}
for (int i = m; i <= n; i++) {
if (prime[i]) {
System.out.println(i);
}
}
}
}