제출 #1313700

#제출 시각아이디문제언어결과실행 시간메모리
1313700chithanhnguyenToys (CEOI18_toy)C++20
100 / 100
355 ms4304 KiB
/*
Author: Nguyen Chi Thanh - High School for the Gifted - VNU.HCM (i2528)
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second
#define __builtin_popcount __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(x) ((1ll << (x)))

#define debug(a, l, r) for (int _i = (l); _i <= (r); ++_i) cout << (a)[_i] << ' '; cout << '\n';

set<int> vals;
int n, fact[32], k = 1;

void gen(int x, int rem) {
    if (x == k) {
        fact[x] = rem;
        int sum = 0;
        for (int i = 1; i <= k; ++i) sum += fact[i] - 1;
        vals.insert(sum);
        return;
    }

    int cur = fact[x - 1];
    while (1) {
        int prod = 1;
        for (int i = 1; i <= k - x + 1; ++i) prod *= cur;
        if (prod > rem) break;
        if (rem % cur) {++cur;continue;}
        fact[x] = cur;
        gen(x + 1, rem / cur);

        cur++;
    }
}

void solve() {
    cin >> n;
    fact[0] = 2;
    
    k = 1;
    for (; k <= 30; ++k) {
        gen(1, n);
    }

    cout << (int)vals.size() << '\n';
    for (auto u : vals) cout << u << ' ';
}

signed main() {
    #ifdef NCTHANH
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);

    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...