#include <bits/stdc++.h> using namespace std; int Res[300001]; int main(){ int n; cin >> n; vector <int> V; for (int i = 0; i < n;i++){ int a; cin >> a; V.push_back(a); } sort(V.begin(),V.end()); V.push_back(-1); int licz = 1; for (int i = 0; i < V.size() - 1;i++){ if(V[i+1] == V[i]){ licz++; } else{ for (int j = 1; j <= licz;j++){ Res[j] += licz - (licz % j); } licz = 1; } } for (int i = 1; i <= n;i++){ cout << Res[i] << " "; } }
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 | #include <bits/stdc++.h> using namespace std; int Res[300001]; int main(){ int n; cin >> n; vector <int> V; for (int i = 0; i < n;i++){ int a; cin >> a; V.push_back(a); } sort(V.begin(),V.end()); V.push_back(-1); int licz = 1; for (int i = 0; i < V.size() - 1;i++){ if(V[i+1] == V[i]){ licz++; } else{ for (int j = 1; j <= licz;j++){ Res[j] += licz - (licz % j); } licz = 1; } } for (int i = 1; i <= n;i++){ cout << Res[i] << " "; } } |