#include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; vector<int> count_sort(unordered_map<int, int> v) { vector<int> count(v.size() + 1); vector<int> o(v.size()); for (int i = 0; i < v.size(); i++) { count[v[i]]++; } int i = 0; for (int number = v.size(); number >= 1; number--) { for (int j = 0; j < count[number]; j++) { o[i] = number; i++; } } return o; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, input; cin >> n; unordered_map<int, int> count(n + 1); for (int i = 0; i < n; i++) { cin >> input; count[input]++; } //vector<int> o = count_sort(count); int i = 0, left = n, splits = 0; vector<int> countv; countv.reserve(count.size()); for (auto& it : count) { countv.push_back(it.second); } sort(countv.begin(), countv.end()); unordered_map<int, int> count2(n + 1); vector<pair<int, int>>count_comp; for (auto& it : countv) { count2[it]++; } for (auto& it : count2) { count_comp.push_back(make_pair(it.first, it.second)); } //for (auto& it : count_comp) { // cout << it.first << " " << it.second << endl; //} for (int k = 1; k <= n; k++) { int diff = 0; for (auto& i : count_comp) { diff += i.second * (i.first % k); } cout << n - diff << " "; } //for (int j = 0; j < o.size(); j++) { // cout << o[j] << endl; //} }
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 65 66 67 68 69 70 71 72 73 74 75 76 | #include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; vector<int> count_sort(unordered_map<int, int> v) { vector<int> count(v.size() + 1); vector<int> o(v.size()); for (int i = 0; i < v.size(); i++) { count[v[i]]++; } int i = 0; for (int number = v.size(); number >= 1; number--) { for (int j = 0; j < count[number]; j++) { o[i] = number; i++; } } return o; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, input; cin >> n; unordered_map<int, int> count(n + 1); for (int i = 0; i < n; i++) { cin >> input; count[input]++; } //vector<int> o = count_sort(count); int i = 0, left = n, splits = 0; vector<int> countv; countv.reserve(count.size()); for (auto& it : count) { countv.push_back(it.second); } sort(countv.begin(), countv.end()); unordered_map<int, int> count2(n + 1); vector<pair<int, int>>count_comp; for (auto& it : countv) { count2[it]++; } for (auto& it : count2) { count_comp.push_back(make_pair(it.first, it.second)); } //for (auto& it : count_comp) { // cout << it.first << " " << it.second << endl; //} for (int k = 1; k <= n; k++) { int diff = 0; for (auto& i : count_comp) { diff += i.second * (i.first % k); } cout << n - diff << " "; } //for (int j = 0; j < o.size(); j++) { // cout << o[j] << endl; //} } |