-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivisors.cpp
More file actions
43 lines (36 loc) · 759 Bytes
/
Divisors.cpp
File metadata and controls
43 lines (36 loc) · 759 Bytes
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
#include <bits/stdc++.h>
using namespace std;
// Find divisors of n, O(sqrt(n))
template <typename T>
vector<T> divisors(const T n) {
vector<T> d;
for (T i = 1; i * i <= n; i++) {
if (n % i == 0) {
d.push_back(i);
if (i * i != n) {
d.push_back(n / i);
}
}
}
return d;
}
void solve() {
int64_t n;
cin >> n;
vector<int64_t> divs = divisors(n);
sort(divs.begin(), divs.end());
cout << divs.size() << '\n';
for (auto d : divs) {
cout << d << " \n"[d == divs.back()];
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}