Submission #536882

#TimeUsernameProblemLanguageResultExecution timeMemory
536882chicken337Toys (CEOI18_toy)C++17
79 / 100
5073 ms65584 KiB
#include <bits/stdc++.h>
using namespace std;
#define hash long long

set<hash> hset;

hash get(int n, int sum){
    hash res = (hash) n * 1e9l + sum;
    return res;
}

void backtrack(int n, int sum){
    hash now = get(n, sum);
    if(hset.find(now) != hset.end())
        return;
    hset.insert(now);
    for(int k = 2; k <= sqrt(n); k ++){
        int div = n / k;
        if((div * k) == n)
            backtrack(div, sum + k - 1);
    }
    if(n != 1)
        backtrack(1, sum + n - 1);
}

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

    int n; cin >> n;
    backtrack(n, 0);

    set<int> unique;
    for(hash sum : hset)
        if(sum / (hash)1e9l == 1ll)
            unique.insert(sum % (hash)1e9);
    cout << unique.size() << '\n';
    for(int it : unique)
        cout << it << ' ';
}
#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...