Submission #464952

#TimeUsernameProblemLanguageResultExecution timeMemory
464952idk321Toys (CEOI18_toy)C++17
79 / 100
5033 ms58928 KiB

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

unordered_map<int, unordered_set<int>> possibleAt;


void solveFor(int num) {
    if (possibleAt.find(num) != possibleAt.end()) return;
    possibleAt[num].insert(num - 1);
    int cur = 2;
    while (cur * cur <= num) {
        if (num % cur == 0) {
            solveFor(cur);
            solveFor(num / cur);
            for (auto it = possibleAt[cur].begin(); it != possibleAt[cur].end(); it++) {
                for (auto it2 = possibleAt[num / cur].begin(); it2 != possibleAt[num / cur].end(); it2++) {
                    possibleAt[num].insert(*it + *it2);
                }
            }

        }
        cur++;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin  >> n;
    solveFor(n);
    cout << possibleAt[n].size() << "\n";
    vector<int> res(possibleAt[n].begin(), possibleAt[n].end());
    sort(res.begin(), res.end());
    for (int i : res) cout << i << " ";
    cout << "\n";
}
#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...