#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie();
int n;
cin >> n;
map<int, int> m;
vector<int> tab(n + 1);
vector<int> values(n + 1);
int x;
for(int i = 0; i < n; i++){
tab[i] = 0;
values[i] = 0;
cin >> x;
if(m.find(x) != m.end()){
m[x]++;
} else{
m[x] = 1;
}
}
tab[n] = 0;
values[n] = 0;
int maxs = 0;
for(auto const& p : m){
if(p.second > maxs){
maxs = p.second;
}
tab[p.second]++;
}
for(int i = n - 1; i >= 0; i--){
tab[i] = tab[i] + tab[i + 1];
}
values[1] = n;
for(int i = 2; i <= maxs; i++){
for(int j = i; j <= n; j = j + i){
//cout << i << " " << j << " " << tab[j] << '\n';
if(j + i > n){
values[i] += (tab[j]) * j;
}
else {
values[i] += ((tab[j] - tab[j + i])) * j;
}
}
}
for(int i = 1; i <= n; i++){
cout << values[i];
if(i != n){
cout << " ";
}
}
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 55 56 57 58 59 60 | #include <iostream> #include <vector> #include <map> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(); int n; cin >> n; map<int, int> m; vector<int> tab(n + 1); vector<int> values(n + 1); int x; for(int i = 0; i < n; i++){ tab[i] = 0; values[i] = 0; cin >> x; if(m.find(x) != m.end()){ m[x]++; } else{ m[x] = 1; } } tab[n] = 0; values[n] = 0; int maxs = 0; for(auto const& p : m){ if(p.second > maxs){ maxs = p.second; } tab[p.second]++; } for(int i = n - 1; i >= 0; i--){ tab[i] = tab[i] + tab[i + 1]; } values[1] = n; for(int i = 2; i <= maxs; i++){ for(int j = i; j <= n; j = j + i){ //cout << i << " " << j << " " << tab[j] << '\n'; if(j + i > n){ values[i] += (tab[j]) * j; } else { values[i] += ((tab[j] - tab[j + i])) * j; } } } for(int i = 1; i <= n; i++){ cout << values[i]; if(i != n){ cout << " "; } } cout << "\n"; return 0; } |
English