# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124472 | naderjemel | Toys (CEOI18_toy) | C++14 | 1293 ms | 22268 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;
#define INF 1e9
#define fi first
#define se second
typedef long long ll;
int n,rs;
set<int> vis;
map<int,vector<int> > mp;
vector<int> solve(int u){
vector<int> st;
if(vis.count(u)) return mp[u];
int less=sqrt(u);
st.push_back(u-1);
for(int i=2;i<=less;i++){
if(u%i==0){
vector<int> s=solve(u/i);
for(int I:s) st.push_back(I+i-1);
}
}
vis.insert(u);
sort(st.begin(),st.end());
auto last = unique(st.begin(),st.end());
st.erase(last,st.end());
return mp[u]=st;
}
int main(){
scanf("%d",&n);
if(n==1){
printf("1\n0\n");
return 0;
}
vector<int> st=solve(n);
printf("%d\n", (int)st.size());
for(int i:st) printf("%d ", i); printf("\n");
}
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... |