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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
const int N = 1e5+10;
unordered_set<int> dp[N];
int n;
vector<int> ds;
map<int, int> id;
void relax(int x) {
int me = id[x];
for(int i = 0; i < (int)ds.size(); ++i) {
if(n % ((long long)ds[i] * x) == 0) {
int he = id[ds[i] * x];
for(int p : dp[i]) {
for(int q : dp[me]) {
dp[he].insert(p + q);
}
}
}
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 1; i * i <= n; ++i) {
if(n % i == 0) {
ds.push_back(i);
if(i * i < n) ds.push_back(n / i);
}
}
sort(ds.begin(), ds.end());
for(int i = 0; i < (int)ds.size(); ++i) {
id[ds[i]] = i;
dp[i].insert(ds[i] - 1);
}
for(int x : ds) {
relax(x);
}
int s = (int)ds.size() - 1;
vector<int> answers(dp[s].begin(), dp[s].end());
sort(answers.begin(), answers.end());
cout << (int)answers.size() << '\n';
for(int x : answers) cout << x << ' ';
}
Compilation message (stderr)
toy.cpp:4: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
4 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |