-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1016.java
More file actions
35 lines (31 loc) · 1.12 KB
/
1016.java
File metadata and controls
35 lines (31 loc) · 1.12 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long min = sc.nextLong();
long max = sc.nextLong();
// 최댓값과 최솟값의 차이만큼 배열 선언
boolean[] check = new boolean[(int) (max - min + 1)];
// 2의 제곱수인 4부터 max보다 작거나 같은 값까지 반복
for (long i = 2; i * i <= max; i++) {
// 제곱수
long pow = i * i;
long startIndex = min % pow == 0 ? min / pow : min / pow + 1;
//long startIndex = min / pow;
// if (min % pow != 0) {
// // 나머지가 있으면 1을 더해야 min보다 큰 제곱수에서 시작
// startIndex++;
// }
for (long j = startIndex; pow * j <= max; j++) {
check[(int) ((j * pow) - min)] = true;
}
}
int count = 0;
for (int i = 0; i < max - min + 1; i++) {
if (!check[i]) {
count++;
}
}
System.out.println(count);
}
}