-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_1484.java
34 lines (30 loc) · 1.02 KB
/
BOJ_1484.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Main {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1 << 16);
public static void main(String[] args) throws Exception {new Main().solution();}
private void solution() throws Exception {
int g = Integer.parseInt(br.readLine());
List<Integer> square = init(g);
Set<Integer> set = new HashSet<>();
StringBuilder sb = new StringBuilder();
int cnt = 0;
for (int cur : square) {
set.add(cur*cur);
if (!set.contains(cur*cur-g)) continue;
sb.append(cur).append('\n');
cnt++;
}
System.out.print(cnt==0?-1:sb);
}
private List<Integer> init(final int g) {
List<Integer> sq = new ArrayList<>();
int bf = 0;
for (int i = 1; i*i-bf*bf <= g; i++) sq.add(bf = i);
return sq;
}
}