-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcandydivision.java
39 lines (27 loc) · 960 Bytes
/
candydivision.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
35
36
37
38
39
// Brett Fazio
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;
public class candydivision {
public static void main(String[] args) throws IOException {
BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
long in = Long.parseLong(bu.readLine());
TreeSet<Long> set = new TreeSet<>();
set.add(0l);
for (int i = 1; i < (int)(Math.sqrt(in)); i++) {
if (in % (i+1) == 0) {
set.add((long)i);
set.add((long) (in / (i+1)-1));
}
}
set.add(in-1);
while (set.isEmpty() == false) {
out.print(set.pollFirst());
out.print(' ');
}
out.close();
}
}