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 <vector>
#include <set>
#include <algorithm>
#include <map>
#include <cassert>
#include <unordered_set>
using namespace std;
#define sz(x) (int(x.size()))
using vi = vector<int>;
using ll = long long;
// map< int, vector<int> > res;
vi sf;
long long n;
unordered_set<int> res[40'000]; //i*i <= n
unordered_set<int> res2[40'000]; //i*i >= n, access n/i.
vi solved(1+40'000, 0);
vi solved2(1+40'000, 0);
vector<int> factors[40'000];
vector<int> factors2[40'000];
unordered_set<int>& get_res(long long u)
{
if(u*u <= n) return res[u];
else return res2[n/u];
}
vector<int>& get_factors(long long u)
{
if(u*u <= n) return factors[u];
else return factors2[n/u];
}
int& get_solved(long long u)
{
if(u*u <= n) return solved[u];
else return solved2[n/u];
}
void solve(long long i)
{
get_res(i).insert(i-1);
for(ll j: get_factors(i))
{
for(int k: get_res(j))
get_res(i).insert(k + i/j - 1);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
if(n == 1)
{
cout << "1\n 0\n";
return 0;
}
for(int i = 2; i < n; i++)
{
// cerr << i << " " << n%i << ' ' << int(n%i == 0) << '\n';
if(i*i > n) break;
if(n % i == 0)
{
sf.push_back(i);
sf.push_back(n/i);
}
}
sf.push_back(n);
sort(sf.begin(), sf.end());
sf.erase(unique(sf.begin(), sf.end()), sf.end());
// for(int q: sf) cerr << q << ' ';
// cerr << '\n';
for(int a: sf)
for(int b: sf)
if(a < b && b%a==0)
get_factors(b).push_back(a);
for(int a: sf) solve(a);
unordered_set<int> ans = get_res(n);
set<int> A;
for(int a: ans) A.insert(a);
cout << sz(A) << '\n';
for(int r: A) cout << r << ' ';
cout << '\n';
}
# | 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... |