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;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define long unsigned long
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define PI 2*acos(0.0)
map <int, set <int>> memo;
set <int> calc(int n) {
if (memo.count(n)) return memo[n];
set <int> res;
for (int i = 1; i*i <= n; i++) {
if (n%i == 0) {
auto ans1 = calc(i);
for (auto to : ans1) {
res.insert(to+n/i-1);
}
if (i != 1) {
auto ans2 = calc(n/i);
for (auto to : ans2) {
res.insert(to+i-1);
}
}
}
}
memo[n] = res;
return res;
}
void solve() {
int n;
cin >> n;
memo[1].insert(0);
auto ans = calc(n);
cout << sz(ans) << endl;
for (auto to : ans) cout << to << ' ';
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
while (t--) {
solve();
}
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... |