Submission #430541

#TimeUsernameProblemLanguageResultExecution timeMemory
430541PetyToys (CEOI18_toy)C++14
100 / 100
3438 ms4632 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n; unordered_set<int>ans; int nr, d; vector<int>Div; int st[40]; void backt (int prod, int k, int sum) { ans.insert(sum + n / prod - 1); if (prod == n) return; int i; for (i = st[k - 1]; i < d; i++) { ll x = 1ll * prod * Div[i]; if (x > n) break; if (n % x == 0) { st[k] = i; backt(x, k + 1, sum + Div[i] - 1); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL)); cin >> n; //n = 1ll * rand() * rand() % (1000000000 - 100000000 + 1) + 100000000; //cout << n << "\n"; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { if (i > 1) Div.push_back(i); if (i != n / i) Div.push_back(n/i); } } d = Div.size(); sort(Div.begin(), Div.end()); backt(1, 1, 0); cout << ans.size() << "\n"; vector<int>lol; for (auto it : ans) lol.push_back(it); sort(lol.begin(), lol.end()); for (auto it : lol) cout << it << " "; 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...