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 <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
int n;
vector<int> v;
set<int> ans;
map<pair<int, pair<int, int> >, int > memo;
void dp(int N, int i, int summ){
if(N == 1){
ans.insert(summ); return;
}
if(memo[make_pair(N, make_pair(i, summ))] == 1) return;
for(int x = i; x < (int)v.size(); x++){
if(v[x] > N) break;
if(N % v[x] == 0){
dp(N / v[x], x, summ + v[x] - 1);
}
}
memo[make_pair(N, make_pair(i, summ))] = 1;
}
signed main(){
cin >> n;
int f = 1;
while(f <= (int)sqrt(n)){
if(n % f == 0){
if(f != 1) v.push_back(f);
if(n/f != f) v.push_back(n/f);
}
f++;
}
sort(v.begin(), v.end());
dp(n, 0, 0);
cout << (int)ans.size() << "\n";
for(set<int>::iterator it = ans.begin(); it != ans.end(); it++){
cout << (*it) << " ";
}
}
# | 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... |