#include <bits/stdc++.h>
using namespace std;
map <int, int> m;
map<int,int>::iterator it;
const int q=3*1e5+1;
int res[q];
void dzielniki(int n){
for(int i=1; i<=n; i++){
int x=n/i;
x*=i;
res[i]+=x;
}
}
int main(){
int n; cin>>n;
for(int i=1; i<=n; i++){
int x; cin>>x;
it=m.find(x);
if(it==m.end())
m.insert({x,1});
else
it->second++;
}
for(it=m.begin(); it!=m.end(); it++){
//cout<<it->first<<" "<<it->second<<endl;
int k=it->second;
dzielniki(k);
}
for(int i=1; i<=n; i++){
cout<<res[i]<<" ";
}
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 | #include <bits/stdc++.h> using namespace std; map <int, int> m; map<int,int>::iterator it; const int q=3*1e5+1; int res[q]; void dzielniki(int n){ for(int i=1; i<=n; i++){ int x=n/i; x*=i; res[i]+=x; } } int main(){ int n; cin>>n; for(int i=1; i<=n; i++){ int x; cin>>x; it=m.find(x); if(it==m.end()) m.insert({x,1}); else it->second++; } for(it=m.begin(); it!=m.end(); it++){ //cout<<it->first<<" "<<it->second<<endl; int k=it->second; dzielniki(k); } for(int i=1; i<=n; i++){ cout<<res[i]<<" "; } return 0; } |
English