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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18
#define ret return
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
unordered_map <int, unordered_set<int> > dp;
void solve(int n){
dp[n].insert(n-1);
for(int i = 2; i <= sqrt(n); i++){
if(n%i==0){
if(dp[i].empty())solve(i);
if(dp[n/i].empty())solve(n/i);
for(auto it: dp[i]){
for(auto itt: dp[n/i]){
dp[n].insert(it+itt);
}
}
}
}
}
vi ans;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
dp.max_load_factor(0.25);dp.reserve(512);
if(n==1){
cout << 1 << '\n' << 0;
ret 0;
}
solve(n);
cout << dp[n].size() << endl;
for(auto it: dp[n]){
ans.pb(it);
}
sort(ans.begin(),ans.end());
n = ans.size();
for(int i = 0; i < n; i++){
cout << ans[i] << " ";
}
}
# | 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... |