Submission #583680

#TimeUsernameProblemLanguageResultExecution timeMemory
583680talant117408Toys (CEOI18_toy)C++17
100 / 100
2914 ms90340 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'
#define PI                  2*acos(0.0)

map <int, set <int>> memo;

set <int> calc(int n) {
    if (memo.count(n)) return memo[n];
    set <int> res;
    for (int i = 1; i*i <= n; i++) {
        if (n%i == 0) {
            auto ans1 = calc(i);
            for (auto to : ans1) {
                res.insert(to+n/i-1);
            }
            if (i != 1) {
                auto ans2 = calc(n/i);
                for (auto to : ans2) {
                    res.insert(to+i-1);
                }
            }
        }
    }
    memo[n] = res;
    return res;
}

void solve() {
    int n;
    cin >> n;
    memo[1].insert(0);
    auto ans = calc(n);
    cout << sz(ans) << endl;
    for (auto to : ans) cout << to << ' ';
}

int main() {
    do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
/*

*/
#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...