Submission #943107

#TimeUsernameProblemLanguageResultExecution timeMemory
943107vjudge1Toys (CEOI18_toy)C++14
59 / 100
5040 ms24896 KiB
#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define int long long

unordered_map<int, map<int, bool> > mp;

vector<int> ans;
int sum = 0;
void f(int n){
    if(mp[n].count(sum)) return;
    mp[n][sum] = true;
    if(n == 1){
        ans.push_back(sum);
        return;
    }
    for(int d = 1; d <= n; d++){
        if(n % d == 0){
            int x = n / d;
            if(x != 1){
                sum = sum + x - 1;
                f(n / x);
                sum = sum - x + 1;
            }
            if(n / d != d){
                x = n / d;
                sum = sum + x - 1;
                f(n / x);
                sum = sum - x + 1;
            }
        }
    }
    
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    f(n);
    sort(all(ans));
    cout << ans.size() << '\n';
    for(auto x : ans) cout << x << ' ';
    
    
    
    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...