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 rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
const int INF = 1000000007;
vi primes;
void sieve() {
bitset<40000> p;
p[0] = p[1] = 1;
for (ll i = 2; i * i <= 1e9; ++i) {
if (p[i]) continue;
primes.pb(i);
for (ll j = i * i; j * j <= 1e9; j += i) p[j] = 1;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
sieve();
int n, p,mult=4;
cin >> n;
if (n == 1) {
cout << "1\n0\n";
return 0;
}
rep(i,0,9)mult*=primes[i];
n=mult;
p = n;
vi factors;
trav(prime, primes) {
while (!(p % prime)) {
factors.pb(prime);
p /= prime;
}
}
if (p == 1) {
p = factors.back();
factors.pop_back();
}
set<vi> dp, dp2;
dp.insert(vi());
set<int> ans;
trav(fac, factors) {
trav(vec, dp) {
rep(i, 0, sz(vec)) {
vi next = vec;
next[i] *= fac;
sort(all(next));
dp2.insert(next);
}
vi next = vec;
next.pb(fac);
sort(all(next));
dp2.insert(next);
}
dp.swap(dp2);
dp2.clear();
}
int fac = p;
trav(vec, dp) {
int sum = -sz(vec) + fac;
trav(num, vec)
sum += num;
ans.insert(sum);
trav(num, vec)
ans.insert(sum + num * fac - fac - num + 1);
}
cout << sz(ans) << endl;
trav(num, ans) cout << num-1 << ' ';
cout << endl;
return 0;
}
Compilation message (stderr)
toy.cpp: In function 'int main()':
toy.cpp:5:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define rep(i, a, b) for (int i = a; i < (b); ++i)
| ^
toy.cpp:73:13: note: in expansion of macro 'rep'
73 | rep(i, 0, sz(vec)) {
| ^~~
# | 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... |