Skip to content

Commit 6b59e79

Browse files
authored
Merge pull request #457 from AlgorithmWithGod/0224LJH
[20250713] BOJ / G1 / 제곱 ㄴㄴ 수 / 이종환
2 parents 2ad2ead + d851a42 commit 6b59e79

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
```java
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.Arrays;
7+
import java.util.StringTokenizer;
8+
9+
public class Main {
10+
static long ans,max,min;
11+
static int len;
12+
static boolean[] powerNoNoNum;
13+
14+
public static void main(String[] args) throws IOException {
15+
init();
16+
process();
17+
print();
18+
}
19+
20+
private static void init() throws IOException {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
StringTokenizer st = new StringTokenizer(br.readLine());
23+
min = Long.parseLong(st.nextToken());
24+
max = Long.parseLong(st.nextToken());
25+
len = (int) (max - min+1);
26+
27+
powerNoNoNum = new boolean[len];
28+
Arrays.fill(powerNoNoNum,true);
29+
ans = 0;
30+
31+
}
32+
33+
private static void process() {
34+
for (long i = 2; i * i <= max; i++){
35+
long powerNum = i * i;
36+
if (powerNum > max) break;
37+
38+
long curIdx;
39+
if (powerNum < min) {
40+
long temp = (min + powerNum - 1) / powerNum;
41+
curIdx = temp * powerNum - min;
42+
} else {
43+
curIdx = powerNum - min;
44+
}
45+
46+
while(curIdx < len){
47+
powerNoNoNum[(int) curIdx] = false;
48+
curIdx += powerNum;
49+
}
50+
}
51+
52+
for (int i = 0; i < powerNoNoNum.length; i++){
53+
if (powerNoNoNum[i]) ans++;
54+
}
55+
}
56+
57+
58+
59+
60+
private static void print() {
61+
System.out.println(ans);
62+
}
63+
64+
65+
66+
}
67+
68+
```

0 commit comments

Comments
 (0)