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;
pair<int,int> factors[100]; //(val, cnt)
int ptr = 0;
void calculateFactors(int n){
int i = 2;
while (i*i<=n){
if (n%i==0){
int fac = i;
int cnt = 0;
while (n%i==0){
n/=i;
cnt++;
}
factors[ptr]={fac,cnt};
ptr++;
}
i+=1;
}
if (n!=1){
factors[ptr]={n,1};
ptr++;
}
}
set<int> vals;
void recurse(int ind, int minval, int curval, int runningtotal, bool zero){
//cout<<ind<<" "<<curval<<" "<<minval<<" "<<runningtotal<<'\n';
if (ind==ptr){
//cout<<"reached end with "<<curval<<'\n';
//have we used everything?
/*bool yes = true;
for (int i = 0; i<ptr; i++){
if (factors[i].second!=0){
yes=false;break;
}
}
if (yes){*/
if (zero){
//we have.
//vals.push_back(runningtotal+(curval-1)-1);
vals.insert(runningtotal+(curval-1)-1);
return;
}
if (curval==1){
return;
//don't care
}
//current total in curval
if (curval<minval){
return;
}
recurse(0, curval, 1, runningtotal+(curval-1), true);
return;
}
int pv = 1;
for (int i = 0; i<=factors[ind].second; i++){
if (factors[ind].second!=0){
zero=false;
}
factors[ind].second-=i;
recurse(ind+1, minval, curval*pv, runningtotal, zero);
factors[ind].second+=i;
pv*=factors[ind].first;
}
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
calculateFactors(n);
/*for (auto p : factors){
cout<<p.first<<' '<<p.second<<'\n';
}*/
recurse(0,1,1,1,true);
//sort(vals.begin(),vals.end());
//vals.erase(unique(vals.begin(),vals.end()), vals.end());
cout<<vals.size()<<'\n';
for (int v : vals){
cout<<v<<' ';
}cout<<'\n';
}
# | 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... |