Skip to content

Commit 2c2a4a5

Browse files
authored
Merge pull request #1950 from AlgorithmWithGod/JHLEE325
[20260220] BOJ / G5 / 다이어트 / 이준희
2 parents 01f0f30 + 23894a7 commit 2c2a4a5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int G = Integer.parseInt(br.readLine());
9+
10+
long low = 1;
11+
long high = 2;
12+
boolean found = false;
13+
StringBuilder sb = new StringBuilder();
14+
15+
while (true) {
16+
long diff = high * high - low * low;
17+
18+
if (high - low == 1 && diff > G) break;
19+
20+
if (diff == G) {
21+
sb.append(high).append("\n");
22+
found = true;
23+
high++;
24+
} else if (diff < G) {
25+
high++;
26+
} else {
27+
low++;
28+
}
29+
}
30+
31+
if (!found) {
32+
System.out.println(-1);
33+
} else {
34+
System.out.print(sb.toString());
35+
}
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)