# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
161392 | rama_pang | Toys (CEOI18_toy) | C++14 | 4345 ms | 86752 KiB |
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;
vector<int> factors;
map<int, set<int>> memo;
set<int> &solve(int n) {
if (memo.count(n)) return memo[n];
auto &ans = memo[n];
if (n == 1) {
ans.emplace(0);
} else {
for (auto &i : factors) {
if (n % i) continue;
auto &nxt = solve(n / i);
for (auto &j : nxt) ans.emplace(j + i - 1);
}
}
return ans;
}
int main() {
int N; scanf("%d", &N);
for (int i = 1; i * i <= N; i++)
if (N % i == 0)
factors.push_back(i), factors.push_back(N / i);
sort(factors.begin(), factors.end());
factors.resize(unique(factors.begin(), factors.end()) - factors.begin());
factors.erase(factors.begin());
set<int> &ans = solve(N);
printf("%d\n", (int)ans.size());
for (auto i : ans) printf("%d ", i);
printf("\n");
}
Compilation message (stderr)
# | 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... |