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;
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define lb lower_bound
#define ub upper_bound
using ll = long long;
using ld = long double;
const int N = 1e5 + 7;
const ll mod = 1e9 + 7;
int n;
set<int> ans;
vi prm ;
vi facto(int x)
{
vi ret;
for (int i = 2; i * i <= x; ++i)
{
while (x % i == 0)
{
ret.pb(i);
x /= i;
}
}
if (x > 1)
ret.pb(x);
return ret;
}
int sum ;
int tkn = 0 ;
void backtrack()
{
if(tkn == (1<<sz(prm)) - 1){
ans.insert(sum) ;
return ;
}
for(int i = 1 ;i < (1<<sz(prm)) ; ++ i ){
if((tkn&i))continue;
int asum = 1 ;
for(int j = 0 ;j < sz(prm) ;++ j){
if(i&(1<<j)){
asum *= prm[j];
}
}
sum+=asum-1;
int omask = tkn ;
tkn|=i ;
backtrack() ;
tkn = omask ;
sum-=asum -1;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
cin >> n;
prm = facto(n);
backtrack();
cout << sz(ans) << "\n";
for (auto u : ans)
{
cout << u << " ";
}
return 0;
}
# | 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... |