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;
set <int> ans;
map <int, set <int>> dp;
set <int> solve(int n) {
if(dp.count(n)) {
return dp[n];
}
int x = sqrt(n);
for(int i = 1; i <= x; i++) {
if(n % i == 0) {
solve(i);
for(auto v : dp[i]) {
dp[n].insert(v + n / i - 1);
}
if(i != 1) {
solve(n / i);
for(auto v : dp[n / i]) {
dp[n].insert(v + i - 1);
}
}
}
}
return dp[n];
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
dp[1].insert(0);
set <int> ans = solve(N);
cout << ans.size() << '\n';
for(auto v : ans) {
cout << v << ' ';
}
return 0;
}
# | 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... |