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++;
}
}
int vals[10000000];
int ptrv = 0;
void recurse(int ind, int minval, int curval, int runningtotal){
//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){
//we have.
vals[ptrv]=(runningtotal+(curval-1)-1);
ptrv++;
return;
}
if (curval==1){
return;
//don't care
}
//current total in curval
if (curval<minval){
return;
}
recurse(0, curval, 1, runningtotal+(curval-1));
return;
}
int pv = 1;
for (int i = 0; i<=factors[ind].second; i++){
factors[ind].second-=i;
recurse(ind+1, minval, curval*pv, runningtotal);
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);
sort(vals,vals+ptrv);
int end = unique(vals,vals+ptrv)-vals;
cout<<end<<'\n';
for (int i = 0; i<end; i++){
cout<<vals[i]<<' ';
}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... |