- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1929.java
More file actions
Latest commit
27 lines (20 loc) · 735 Bytes
/
Copy path1929.java
File metadata and controls
27 lines (20 loc) · 735 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
importjava.util.*;
publicclassMain {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
intm = sc.nextInt();
intn = sc.nextInt();
intprimeCnt = 0;
boolean[] arr = newboolean[n+1]; // false == 지워지지 않음, true == 지워짐
for(inti=2; i<=n; i++) {
if(!(arr[i])) { // 지워지지 않았으면
primeCnt++;
if(i>=m)
System.out.println(i);
for(intj=i*2; j<=n; j+=i) { // j=i*i 로 초기화해도 되지만 n^2이 int 범위를 넘어갈 수 있으므로 2i로 초기화
arr[j] = true; // 같은 수가 여러번 true로 지정됨에 주의
}
}
}
}
}