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
// Fryderyk Brajer
#include <bits/stdc++.h>
using namespace std;

using llong = long long;
using pii = pair<int, int>;
constexpr int max_n = 3e5 + 5;
constexpr int mod = 1e9 + 7;

int arr[max_n];
int n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    copy_n(istream_iterator<int>(cin), n, arr);

    sort(arr, arr + n);
    vector<int> vec;

    int cnt{1};
    for (int i = 0; i < n - 1; ++i)
    {
        if (arr[i] == arr[i + 1])
        {
            arr[i] = 0;
            ++cnt;
            continue;
        }

        vec.push_back(cnt);
        cnt = 1;
    }
    vec.push_back(cnt);

    int max_cnt = *ranges::max_element(vec);

    int buc[max_n]{};
    for (int e : vec)
        ++buc[e];

    partial_sum(buc, buc + max_cnt + 1, buc);

    for (int i = 1; i <= n; ++i)
    {
        if (i > max_cnt)
        {
            cout << 0 << ' ';
            continue;
        }

        int sum{};
        for (int j = 1; i * j <= max_cnt; ++j)
        {
            int cnt = buc[min(i * j + i - 1, max_cnt)] - buc[i * j - 1];
            sum += j * cnt;
        }

        cout << i * sum << ' ';
    }
}