You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 15 | 1;
bool notprime[N];
long long primes[N], pcnt;
long long sel[N][2], scnt;
set<long long> S;
void dfs(int st, long long x) {
if (st == scnt) {
//printf("## %lld\n", x);
S.insert(x);
} else
for (int i = 0; i <= sel[st][1]; i++) {
dfs(st + 1, x);
x *= sel[st][0];
}
}
int main() {
notprime[0] = notprime[1] = true;
for (long long i = 2; i < N; i++)
if (!notprime[i]) {
primes[pcnt++] = i;
for (long long j = i * i; j < N; j += i)
notprime[j] = true;
}
int n;
scanf("%d", &n);
int x = n;
for (int i = 0; i < pcnt && primes[i] * primes[i] <= n && x > 1; i++) {
if (x % primes[i] == 0) {
sel[scnt][0] = primes[i];
while (x % primes[i] == 0)
sel[scnt][1]++, x /= primes[i];
scnt++;
}
}
if (x != 1) sel[scnt][0] = x, sel[scnt][1]++, scnt++;
//for (int i = 0; i < scnt; i++) printf("** %lld %lld\n", sel[i][0], sel[i][1]);
dfs(0, 1);
for (auto xx:S) {
auto d = n / xx;
auto ans = (1 + n + 1 - d) * (n / d) / 2;
printf("%lld ", ans);
}
/*for (int k = n / 2; k <= n; k++) {
int d = gcd(n, k);
int ans = (1 + n + 1 - d) * (n / d) / 2;
//printf("** %d %d %d\n", n, k, ans);
}*/
return 0;
}