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 <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
#define sz(x) (int(x.size()))
using vi = vector<int>;
map< int, vector<int> > res;
vector<int> solve(int i)
{
// cerr << "solve " << i << '\n';
if(res.find(i) != res.end()) return res[i];
vi ans(1, i-1);
for(int j = 2; j < i && j*j <= i; j++)
{
if(i % j == 0)
{
int u = j;
int v = i/j;
vi su = solve(u);
vi sv = solve(v);
for(int a: su)
for(int b: sv)
ans.push_back(a+b);
}
}
sort(ans.begin(), ans.end());
ans.erase(unique(ans.begin(), ans.end()), ans.end());
res[i] = ans;
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
// vector<int> res[1+n];
// for(int i = 1; i <= n; i++)
// {
// res[i].push_back(i-1);
// for(int j = 1; j < i && j*j <= i; j++)
// {
// if(i % j == 0)
// {
// int u = j;
// int v = i/j;
// for(int a: res[u])
// for(int b: res[v])
// res[i].push_back(a+b);
// // break;
// }
// }
// // sort(res[i].begin(), res[i].end());
// // res[i].erase(unique(res[i].begin(), res[i].end()), res[i].end());
//
// // cerr << i << " : " << sz(res[i]) << '\n';
// }
vi ans = solve(n);
cout << sz(ans) << '\n';
for(int r: ans) cout << r << ' ';
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... |