-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEveryone_is_a_Winner.java
More file actions
169 lines (147 loc) · 3.98 KB
/
Everyone_is_a_Winner.java
File metadata and controls
169 lines (147 loc) · 3.98 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import java.util.*;
import java.io.*;
/*
https://codeforces.com/problemset/problem/1263/C
*/
public class Everyone_is_a_Winner {
public static void main(String[] str) {
boolean muiltTestCases = true;
var cin = new FastScanner();
PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));
int n = 1;
if (muiltTestCases)
n = cin.nextInt();
var s = new testCaseSolution(cin, cout);
while (n-- > 0) {
s.solve();
cout.println();
}
cout.flush();
}
}
class testCaseSolution {
private int[][] mem;
private FastScanner cin;
PrintWriter cout;
public testCaseSolution(FastScanner cin, PrintWriter cout) {
this.cin = cin;
this.cout = cout;
}
class elem implements Comparable<elem> {
public int value;
public int index;
public elem(int value, int index) {
this.value = value;
this.index = index;
}
public int compareTo(elem e) {
return Integer.compare(this.value, e.value);
}
}
void solve() {
int n = cin.nextInt();
var res = new ArrayList<Integer>();
res.add(0);
int divider = 1;
while (divider <= n) {
res.add(n / divider);
int x = n / divider;
int treshold = n / x + 1;
divider = treshold;
}
cout.println((res.size()));
Collections.sort(res, (a, b) -> a - b);
for (var x : res)
cout.print(x + " ");
}
}
final class Algo {
private Algo() {
}
// O(log(n))
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
// O(log(sqrt(n))
public static TreeSet<Integer> getDivisors(int n) {
var st = new TreeSet<Integer>();
for (int i = 1; i * i <= n; i++) {
if (n % i == 0)
st.add(i);
if (n % (n / i) == 0)
st.add(n / i);
}
return st;
}
// O(n(log(log(N)))
public static ArrayList<Integer> primesTill_N(int n) {
var ans = new ArrayList<Integer>();
var prime = new ArrayList<Integer>(n + 1);
for (int i = 0; i < n + 1; i++)
prime.add(1);
for (int p = 2; p * p <= n; p++) {
if (prime.get(p) == 1) {
for (int i = p * p; i <= n; i += p)
prime.set(i, 0);
}
}
for (int p = 2; p <= n; p++)
if (prime.get(p) == 1)
ans.add(p);
return ans;
}
// O(sqrt(N))
public static TreeMap<Integer, Integer> getPrimeFactors(int n) {
var ans = new TreeMap<Integer, Integer>();
var primes = primesTill_N((int) (Math.sqrt(n) + 1));
for (int p : primes) {
while (n % p == 0) {
ans.putIfAbsent(p, 0);
ans.put(p, ans.get(p) + 1);
n /= p;
}
}
if (n > 2) {
ans.putIfAbsent(n, 0);
ans.put(n, ans.get(n) + 1);
}
return ans;
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}