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;
set<pair<int,int>> dp;
vector<pair<int,int>> v;
vector<int> sol;
int n;
void solve(int bm , int cnt , int mult , int pos , int x){
if(pos == v.size()){
if(mult < x || mult == 1){
return ;
}
if(bm == 1){
sol.push_back(cnt+mult-1);
return ;
}
solve(bm,cnt+mult-1,1,0,mult);
return ;
}
if(pos == 0 && mult == 1){
if(dp.find({bm,cnt}) != dp.end()){
return ;
}
dp.insert({bm,cnt});
}
solve(bm,cnt,mult,pos+1,x);
if(bm%v[pos].first == 0){
solve(bm/v[pos].first,cnt,mult*v[pos].first,pos,x);
}
}
int main(){
cin >> n;
int nn = n;
if(n == 1){
cout << 1 << endl << 0 << endl;
return 0;
}
for(int i = 2 ; i*i <= n ; i += 1){
if(n%i == 0){
int cnt = 0;
while(n%i == 0){
n /= i;
cnt += 1;
}
v.push_back({i,cnt});
}
}
if(n > 1){
v.push_back({n,1});
}
solve(nn,0,1,0,1);
sort(sol.begin(),sol.end());
sol.erase(unique(sol.begin(),sol.end()),sol.end());
cout << sol.size() << endl;
for(int i : sol){
cout << i << " ";
}cout << endl;
}
Compilation message (stderr)
toy.cpp: In function 'void solve(int, int, int, int, int)':
toy.cpp:9:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | if(pos == v.size()){
| ~~~~^~~~~~~~~~~
# | 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... |