# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007876 | canonica1 | Toys (CEOI18_toy) | C++17 | 4966 ms | 87688 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 <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
vector<int> ans;
vector<int> factors;
vector<vector<int>> g;
vector<set<int>> M;
void rec(int n, int answer) {
if(M[n].count(answer)) return;
M[n].insert(answer);
if (factors[n] == 1) {
ans.push_back(answer);
return;
}
for(auto d : g[n]) {
rec(d, answer + factors[n] / factors[d] - 1);
}
}
int main() {
int n;
cin >> n;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
factors.push_back(i);
if (i * i != n) {
factors.push_back(n / i);
}
}
}
sort(factors.begin(), factors.end());
g.resize(factors.size());
M.resize(factors.size());
for(int i = 0; i < factors.size(); i++){
for(int j = i + 1; j < factors.size(); j++){
if(factors[j] % factors[i] == 0){
g[j].push_back(i);
}
}
}
rec(factors.size() - 1, 0);
sort(ans.begin(), ans.end());
cout << ans.size() << endl;
for (auto x : ans) {
cout << x << " ";
}
}
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... |