Skip to content

Commit 718b5cd

Browse files
authored
Merge pull request #953 from AlgorithmWithGod/Ukj0ng
[20250922] BOJ / G5 / 멍멍이 쓰다듬기 / 한종욱
2 parents f4ef3b0 + b68e8dc commit 718b5cd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static long X, Y, diff;
9+
10+
public static void main(String[] args) throws IOException {
11+
init();
12+
long answer = solve();
13+
bw.write(answer + "\n");
14+
bw.flush();
15+
bw.close();
16+
br.close();
17+
}
18+
19+
private static void init() throws IOException {
20+
StringTokenizer st = new StringTokenizer(br.readLine());
21+
X = Long.parseLong(st.nextToken());
22+
Y = Long.parseLong(st.nextToken());
23+
diff = Y - X;
24+
}
25+
26+
private static long solve() {
27+
if (diff == 0) {
28+
return 0;
29+
}
30+
31+
long k = (long) Math.sqrt(diff);
32+
33+
if (k * k == diff) {
34+
return 2 * k - 1;
35+
} else if (diff <= k * k + k) {
36+
return 2 * k;
37+
} else {
38+
return 2 * k + 1;
39+
}
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)