제출 #688561

#제출 시각아이디문제언어결과실행 시간메모리
688561four_specksToys (CEOI18_toy)C++17
100 / 100
1942 ms4444 KiB
#include <bits/stdc++.h>

using namespace std;

namespace
{
    template <typename Fun>
    struct YCombinator
    {
        template <typename T>
        YCombinator(T &&_fun) : fun(forward<T>(_fun)) {}

        template <typename... Args>
        decltype(auto) operator()(Args &&...args) { return fun(ref(*this), forward<Args>(args)...); }

    private:
        Fun fun;
    };

    template <typename T>
    YCombinator(T &&) -> YCombinator<decay_t<T>>;

} // namespace

void solve()
{
    int n;
    cin >> n;

    vector res = YCombinator(
        [&](auto self, int x, int g) -> vector<int>
        {
            vector<int> ret;
            ret.push_back(x - 1);
            for (int f = g; f * f <= x; f++)
            {
                if (x % f == 0)
                {
                    {
                        vector cur = self(x / f, f);
                        for (int z : cur)
                            ret.push_back(z + f - 1);
                    }
                    if (f * f != x)
                    {
                        int y = x / f;

                        vector cur = self(f, y);
                        for (int z : cur)
                            ret.push_back(z + y - 1);
                    }
                }
            }

            sort(ret.begin(), ret.end());
            ret.erase(unique(ret.begin(), ret.end()), ret.end());

            return ret;
        })(n, 2);

    cout << (int)res.size() << '\n';
    for (int x : res)
        cout << x << ' ';
    cout << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

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