Submission #949545

#TimeUsernameProblemLanguageResultExecution timeMemory
949545glebustimToys (CEOI18_toy)C++17
59 / 100
5016 ms1044 KiB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

unordered_set<int> solve(int x) {
    unordered_set<int> r;
    r.insert(x - 1);
    int y = 2;
    while (y * y <= x) {
        if (x % y == 0) {
            int z = x / y;
            unordered_set a = solve(y);
            for (int b: a)
                r.insert(b + z - 1);
            a = solve(z);
            for (int b: a)
                r.insert(b + y - 1);
        }
        ++y;
    }
    return r;
}

int main() {
    fast;
    int n;
    cin >> n;
    unordered_set<int> a = solve(n);
    vi ans;
    for (int x: a)
        ans.push_back(x);
    sort(all(ans));
    cout << ans.size() << '\n';
    for (int x: ans)
        cout << x << ' ';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...