This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int> factors;
map<int, set<int>> memo;
set<int> &solve(int n) {
if (memo.count(n)) return memo[n];
auto &ans = memo[n];
if (n == 1) {
ans.emplace(0);
} else {
for (auto &i : factors) {
if (n % i) continue;
auto &nxt = solve(n / i);
for (auto &j : nxt) ans.emplace(j + i - 1);
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int N; cin >> N;
for (int i = 1; i * i <= N; i++)
if (N % i == 0)
factors.push_back(i), factors.push_back(N / i);
sort(factors.begin(), factors.end());
factors.resize(unique(factors.begin(), factors.end()) - factors.begin());
factors.erase(factors.begin());
set<int> &ans = solve(N);
cout << ans.size() << "\n";
for (auto i : ans) cout << i << " ";
cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |