#include <bits/stdc++.h> using namespace std; int tab[300007]; int grupy[300007]; vector<int> A; int suma(int i) { int d=0; for (int j = 0; j < A.size(); ++i) { d += i * (A[j] / i); } return d; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> tab[i]; } sort(tab, tab + n); int ostatni = -8; int licznik = 0; //vector<int> A; for (int i = 0; i < n+1; ++i) { if (tab[i] == ostatni) { ++licznik; } else if (tab[i] != ostatni) { //grupy[i - 1] = licznik; A.push_back(licznik); licznik = 1; ostatni = tab[i]; } } int su = 0; for (int i = 0; i < A.size(); ++i) { grupy[i] = A[i]; } for (int i = 1; i <= n; ++i) { su = 0; for (int j = 1; j <= A.size(); ++j) { su += grupy[j] / i; } cout << su * i << " "; } cout << endl; /* // wypisujemy wynik for (int i = 1; i <= n; ++i) { cout << suma(i) << " "; } //debuhg for (int i = 0; i < n+3; ++i) { cout << tab[i] << " "; } cout << endl; for (int i = 0; i < n + 3; ++i) { cout << grupy[i] << " "; } cout << endl; for (int i = 0; i < A.size(); ++i) { cout << A[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 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #include <bits/stdc++.h> using namespace std; int tab[300007]; int grupy[300007]; vector<int> A; int suma(int i) { int d=0; for (int j = 0; j < A.size(); ++i) { d += i * (A[j] / i); } return d; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> tab[i]; } sort(tab, tab + n); int ostatni = -8; int licznik = 0; //vector<int> A; for (int i = 0; i < n+1; ++i) { if (tab[i] == ostatni) { ++licznik; } else if (tab[i] != ostatni) { //grupy[i - 1] = licznik; A.push_back(licznik); licznik = 1; ostatni = tab[i]; } } int su = 0; for (int i = 0; i < A.size(); ++i) { grupy[i] = A[i]; } for (int i = 1; i <= n; ++i) { su = 0; for (int j = 1; j <= A.size(); ++j) { su += grupy[j] / i; } cout << su * i << " "; } cout << endl; /* // wypisujemy wynik for (int i = 1; i <= n; ++i) { cout << suma(i) << " "; } //debuhg for (int i = 0; i < n+3; ++i) { cout << tab[i] << " "; } cout << endl; for (int i = 0; i < n + 3; ++i) { cout << grupy[i] << " "; } cout << endl; for (int i = 0; i < A.size(); ++i) { cout << A[i] << " "; } */ return 0; } |