# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
654054 | MasterTaster | Toys (CEOI18_toy) | C++14 | 0 ms | 0 KiB |
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 <algorithm>
#define ll long long
#define pb push_back
using namespace std;
ll n;
vector<ll> svi, ress;
void dfs(ll x, vector<ll> &d, ll i, ll sum)
{
if (x==1) return;
ress.pb(sum+x-1);
vector<ll> dd;
while (i<d.size())
{
if (x%d[i]==0) dd.pb(d[i]);
i++;
}
for (int i=0; i<dd.size(); i++)
{
if (x/dd[i]>=dd[i])
dfs(x/dd[i], dd, i, sum+dd[i]-1);
}
}
map<ll, bool> bio;
int main() {
cin>>n;
if (n==1) { cout<<1<<endl<<0; exit(0); }
for (ll i=2; i*i<=n; i++)
if (n%i==0) svi.pb(i);
dfs(n, svi, 0, 0);
vector<ll> r;
for (int i=0; i<ress.size(); i++) if (!bio[ress[i]]) { bio[ress[i]]=true; r.pb(ress[i]); }
cout<<r.size()<<endl;
sort(r.begin(), r.end());
for (int i=0; i<r.size(); i++) cout<<r[i]<<" ";
}