Submission #161391

#TimeUsernameProblemLanguageResultExecution timeMemory
161391rama_pangToys (CEOI18_toy)C++14
100 / 100
4195 ms86776 KiB
#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() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int N; cin >> 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); cout << ans.size() << "\n"; for (auto i : ans) cout << i << " "; cout << "\n"; }
#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...