1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
| #include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL;
const int Ni = 44721;
const int maxn = Ni + 2;
const LL N = Ni;
int cnt, tot;
bool vis[maxn];
LL n, p[maxn], dst[maxn];
inline LL ksm(LL a, LL b, LL c) {
LL ret = 1ll, tmp = a % c;
while (b) {
if (b & 1ll) ret = (ret * tmp) % c;
tmp = (tmp * tmp) % c;
b >>= 1ll;
}
return ret;
}
inline LL gr(LL x) {
LL ret;
for (int i = 0; i < 4; ++i) ret ^= rand() << (16 * i);
if (ret < 0) ret = -ret;
return ret % (x - 2ll) + 2ll;
}
inline bool isprime(LL x) {
for (int k = 0; k < 4; ++k)
if (ksm(gr(x), x - 1ll, x) != 1ll)
return false;
return true;
}
inline void shake() {
for (int i = 2; i <= Ni; ++i) {
if (!vis[i]) p[cnt++] = i;
for (int j = 0; j < cnt; ++j) {
if (p[j] * LL(i) > N) break;
vis[p[j] * i] = true;
}
}
}
inline LL sqr(LL x) { return x * x; }
void dfs(int now, LL cur, LL left) {
if (left == 1ll) {
dst[tot++] = cur;
return;
}
if (sqr(left - 1ll) >= n && isprime(left - 1ll)) dst[tot++] = cur * (left - 1ll);
LL tmp, sum; int i;
for (i = now; p[i] <= left && p[i] * p[i] <= n; ++i) {
tmp = p[i]; sum = tmp + 1ll;
while (sum <= left) {
if (left % sum == 0) dfs(i + 1, cur * tmp, left / sum);
tmp *= p[i];
sum += tmp;
}
}
}
int main() {
srand(20000926); shake(); p[cnt] = 1000000007;
while (scanf("%lld", &n) == 1) {
tot = 0; dfs(0, 1ll, n);
sort(dst, dst + tot);
tot = unique(dst, dst + tot) - dst;
printf("%d\n", tot);
if (tot != 0) {
printf("%lld", dst[0]); for (int i = 1; i < tot; ++i) printf(" %lld", dst[i]);
putchar('\n');
}
}
}
|