#include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; typedef long long ll; unordered_map<ll, ll> um; const ll limit = 3000009; ll ilosci[limit], odp[limit]; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ll n, a; cin >> n; for(ll i = 0; i < n; i++){ cin >> a; um[a]++; } for(auto& i : um){ ilosci[i.second]++; } vector<pair<ll, ll>> ok; for(ll i = 1; i <= n; i++){ if(ilosci[i] != 0) ok.push_back({i, ilosci[i]}); } for(auto i : ok){ for(ll j = 1; j <= i.first; j++){ odp[j] += i.second * i.first - (i.first % j); } } for(ll i = 1; i <= n; i++) cout << odp[i] << ' '; 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 | #include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; typedef long long ll; unordered_map<ll, ll> um; const ll limit = 3000009; ll ilosci[limit], odp[limit]; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ll n, a; cin >> n; for(ll i = 0; i < n; i++){ cin >> a; um[a]++; } for(auto& i : um){ ilosci[i.second]++; } vector<pair<ll, ll>> ok; for(ll i = 1; i <= n; i++){ if(ilosci[i] != 0) ok.push_back({i, ilosci[i]}); } for(auto i : ok){ for(ll j = 1; j <= i.first; j++){ odp[j] += i.second * i.first - (i.first % j); } } for(ll i = 1; i <= n; i++) cout << odp[i] << ' '; cout << "\n"; return 0; } |