Submission #1029367

#TimeUsernameProblemLanguageResultExecution timeMemory
1029367NValchanovToys (CEOI18_toy)C++17
59 / 100
5029 ms187968 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; const ll MAXN = 1e9 + 10; unordered_map < ll, unordered_map < ll, bool > > dp; ll n, m; vector < ll > divs; void read() { cin >> n; } void fill_divs() { for(ll i = 2; i * i <= n; i++) { if(n % i == 0) { divs.push_back(i); if(i * i != n) divs.push_back(n / i); } } divs.push_back(n); m = divs.size(); sort(divs.begin(), divs.end()); } void rec(ll cur, ll sum, ll last) { if(dp[cur][sum]) return; dp[cur][sum] = true; if(cur == n) return; for(ll i = last; i < m; i++) { ll d = divs[i]; if(cur * d > n) continue; if(!dp[cur * d][sum + d - 1]) rec(cur * d, sum + d - 1, i); } } void print() { vector < int > p; for(auto x : dp[n]) { p.push_back(x.first); } sort(p.begin(), p.end()); cout << p.size() << endl; for(int x : p) { cout << x << " "; } cout << endl; } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); fill_divs(); rec(1, 0, 0); print(); 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...