Skip to content

Commit 3e4decb

Browse files
authored
Merge pull request #859 from AlgorithmWithGod/lkhyun
[20250910] BOJ / G1 / 제곱 ㄴㄴ수 / 이강현
2 parents 73d475b + 098aa62 commit 3e4decb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static StringBuilder sb = new StringBuilder();
10+
static long min,max;
11+
static List<Long> squares;
12+
static long cnt;
13+
public static void main(String[] args) throws Exception {
14+
st = new StringTokenizer(br.readLine());
15+
min = Long.parseLong(st.nextToken());
16+
max = Long.parseLong(st.nextToken());
17+
squares = new ArrayList<>();
18+
cnt = max-min+1;
19+
20+
long temp = 2;
21+
while(temp*temp<=max){ //제곱수 저장
22+
squares.add(temp*temp);
23+
temp++;
24+
}
25+
26+
Set<Long> s = new HashSet<>();
27+
28+
for (long cur : squares) {
29+
long init = min/cur;
30+
long result = cur*init++;
31+
if(min%cur == 0) s.add(result);
32+
result = cur*init;
33+
while(result<=max){
34+
s.add(result);
35+
result = ++init * cur;
36+
}
37+
}
38+
39+
bw.write((cnt - s.size())+"");
40+
bw.close();
41+
}
42+
43+
}
44+
```

0 commit comments

Comments
 (0)