# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
426338 | linkret | Toys (CEOI18_toy) | C++14 | 5066 ms | 75732 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 <bits/stdc++.h>
using namespace std;
map <int, int> m; set <int> dp [100000]; vector <int> dj; int n;
set <int> rek (int x){
//cout << x << endl;
set <int> s;
if (dp[m[x]].size()!=0) return dp[m[x]];
if (x==1) return {0};
for (int i=0; i<dj.size(); i++){
if (sqrt(x)<dj[i]) break;
else if (x%dj[i]==0){
set <int> s3, s2;
if (i!=0){
s2=rek (x/dj[i]);
for (auto it:s2) s3.insert (it+dj[i]-1);
}
s2=rek (x/(x/dj[i]));
for (auto it:s2) s3.insert (it+(x/dj[i])-1);
for (auto e : s3)
s.insert(e);
}
}
return dp [m[x]]=s;
}
int main(){
cin >> n; int now=0;
dj.push_back(n);
for (int i=1; i<=sqrt (n); i++){
if (n%i==0){
m [i]=now; m[n/i]=now+1; now+=2;
dj.push_back(i); dj.push_back(n/i);
}
}
sort (dj.begin(), dj.end());
set <int> ans = rek (n);
cout << ans.size() << endl;
for (auto it:ans) cout << it << " ";
}
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... |