Submission #1345945

#TimeUsernameProblemLanguageResultExecution timeMemory
1345945kawhietToys (CEOI18_toy)C++20
59 / 100
5093 ms1448 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif

#define int long long

int power(int a, int b, int n) {
    int res = 1;
    while (b > 0) {
        if (b & 1) {
            res *= a;
            if (res > n) return -1; 
        }
        a = (1LL * a * a);
        b >>= 1;
    }
    return res;
}

set<int> s;

void go(int n, int cnt, int sum, int prv) {
    if (n == 1) {
        s.insert(sum);
        return;
    }
    if (cnt == 0) {
        return;
    }
    for (int x = prv; ; x++) {
        if (power(x, cnt, n) == -1) {
            break;
        }
        if (n % x > 0) continue;
        go(n / x, cnt - 1, sum + x - 1, x);
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    go(n, 30, 0, 1);
    cout << s.size() << '\n';
    for (auto x : s) {
        cout << x << ' ';
    }
    cout << '\n';
    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...