File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments