Submission #806566

#TimeUsernameProblemLanguageResultExecution timeMemory
806566Valaki2Toys (CEOI18_toy)C++14
100 / 100
791 ms4516 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back int n; set<int> ans; vector<int> all; void backtrack(int idx, int num, int sum) { int cur = all[idx]; if(cur == 1) { if(num == 1) { ans.insert(sum); } return; } backtrack(idx - 1, num, sum); while(num % cur == 0) { num /= cur; sum += cur - 1; backtrack(idx - 1, num, sum); } } void solve() { cin >> n; for(int i = 1; i * i <= n; i++) { if(n % i == 0) { all.pb(i); if(i * i != n) { all.pb(n / i); } } } sort(all.begin(), all.end()); backtrack(all.size() - 1, n, 0); cout << ans.size() << "\n"; for(int cur : ans) { cout << cur << " "; } cout << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); 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...