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;
#define int long long
int n;
vector<int> v;
set<int> ans;
map<pair<int, pair<int, pair<int, int> > >, int> memo;
int temp[100000];
void dp(int idx, int curr, int fake, int end){
if(idx == (int)v.size()){
ans.insert(curr - end - 1);
return;
}
if(memo[make_pair(idx, make_pair(curr, make_pair(fake, end)))] == 1) return;
temp[end + 1] = v[idx];
dp(idx + 1, curr + v[idx], end + 1, end + 1);
temp[end + 1] = 0;
if(idx != (int)v.size() - 1 && v[idx] == v[idx + 1]){
for(int i = end; i >= 0; i--){
temp[i] *= v[idx];
dp(idx + 1, curr + temp[i] - temp[i] / v[idx], i, end);
temp[i] /= v[idx];
}
memo[make_pair(idx, make_pair(curr, make_pair(fake, end)))] = 1;
return;
}
for(int i = end; i >= 0; i--){
temp[i] *= v[idx];
dp(idx + 1, curr + temp[i] - temp[i] / v[idx], end, end);
temp[i] /= v[idx];
}
memo[make_pair(idx, make_pair(curr, make_pair(fake, end)))] = 1;
}
signed main(){
cin >> n;
int f = 2;
while(f <= (int)sqrt(n) + 1 && n > 1){
if(n % f == 0){
v.push_back(f);
n = n/f;
}
else f++;
}
if(n > 1) v.push_back(n);
dp(0, 0, -1, -1);
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... |