Skip to content

Commit d9ddee7

Browse files
authored
[20251031] BOJ / G5 / 다이어트 / 이종환
1 parent 8230d92 commit d9ddee7

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.Arrays;
6+
7+
public class Main {
8+
9+
static long diff;
10+
static StringBuilder sb = new StringBuilder();
11+
12+
13+
public static void main(String[] args) throws IOException {
14+
init();
15+
process();
16+
print();
17+
}
18+
19+
private static void init() throws IOException{
20+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));;
21+
diff = Integer.parseInt(br.readLine());
22+
}
23+
24+
private static void process() {
25+
26+
long pre =1l;
27+
boolean isEmpty = true;
28+
for (long i = 2; i <= 500000; i++) {
29+
long num = i*i;
30+
if (num - pre > diff) break;
31+
pre = num;
32+
33+
long target = num - diff;
34+
if (target == 0) continue;
35+
long sqrt = (long) Math.sqrt(target);
36+
if (sqrt*sqrt != target) continue;
37+
isEmpty = false;
38+
sb.append(i).append("\n");
39+
40+
41+
42+
}
43+
44+
if(isEmpty)sb.append("-1");
45+
46+
}
47+
48+
49+
50+
private static void print() {
51+
System.out.println(sb.toString());
52+
}
53+
}
54+
55+
56+
```

0 commit comments

Comments
 (0)