This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |