#include<bits/stdc++.h>
using namespace std;
map<int,int> tmpm;
int tab[300010];
int pref[600010];
int main(){
// cin.tie(0);
// ios_base::sync_with_stdio(false);
int n; cin >> n;
int tmp;
for(int i = 0; i < n; i++){
cin >> tmp;
tmpm[tmp]++;
}
int m = 0;
for(auto x : tmpm){
// cout << x.first << " " << x.second << "\n";
tab[m] = x.second;
m++;
}
sort(tab,tab + m);
int limit = tab[m-1];
tab[m] = 1e9;
int ptr1 = 0;
pref[0] = 0;
for(int i = 1; i <= 2 * n; i++){
pref[i] = pref[i-1];
while(tab[ptr1] == i){
pref[i]++;
ptr1++;
}
}
// for(int i = 0; i <= 2 * n; i++){
// cout << pref[i] << " ";
// }
// cout << "\n";
for(int i = 1; i <= n; i++){
int ans = 0;
for(int j = i-1,ctr1 = 1; j < n; j += i,ctr1++){
ans += (pref[j + i] - pref[j]) * i * ctr1;
// printf("pref[%d] = %d, pref[%d] = %d\n",j+i,pref[j+i],j,pref[j]);
}
// cout << endl;
cout << ans << " ";
// cout << endl;
}
cout << "\n";
return 0;
}
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 | #include<bits/stdc++.h> using namespace std; map<int,int> tmpm; int tab[300010]; int pref[600010]; int main(){ // cin.tie(0); // ios_base::sync_with_stdio(false); int n; cin >> n; int tmp; for(int i = 0; i < n; i++){ cin >> tmp; tmpm[tmp]++; } int m = 0; for(auto x : tmpm){ // cout << x.first << " " << x.second << "\n"; tab[m] = x.second; m++; } sort(tab,tab + m); int limit = tab[m-1]; tab[m] = 1e9; int ptr1 = 0; pref[0] = 0; for(int i = 1; i <= 2 * n; i++){ pref[i] = pref[i-1]; while(tab[ptr1] == i){ pref[i]++; ptr1++; } } // for(int i = 0; i <= 2 * n; i++){ // cout << pref[i] << " "; // } // cout << "\n"; for(int i = 1; i <= n; i++){ int ans = 0; for(int j = i-1,ctr1 = 1; j < n; j += i,ctr1++){ ans += (pref[j + i] - pref[j]) * i * ctr1; // printf("pref[%d] = %d, pref[%d] = %d\n",j+i,pref[j+i],j,pref[j]); } // cout << endl; cout << ans << " "; // cout << endl; } cout << "\n"; return 0; } |
English