#include <cstdio> #include <algorithm> #include <vector> using namespace std; int n, a[300001], wynik[300001]; vector<int> v; int main() { scanf("%d", &n); for (int i=1; i<=n; i++) scanf("%d", &a[i]); sort(a+1, a+n+1); int ost = 0; for (int i=1; i<=n; i++) { if (i == n || a[i] != a[i+1]) { v.push_back(i-ost); ost = i; } } for (int s: v) { for (int i=1; i<=s; i++) { wynik[i] += s - s%i; } } for (int i=1; i<=n; i++) printf("%d ", wynik[i]); puts(""); }
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 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; int n, a[300001], wynik[300001]; vector<int> v; int main() { scanf("%d", &n); for (int i=1; i<=n; i++) scanf("%d", &a[i]); sort(a+1, a+n+1); int ost = 0; for (int i=1; i<=n; i++) { if (i == n || a[i] != a[i+1]) { v.push_back(i-ost); ost = i; } } for (int s: v) { for (int i=1; i<=s; i++) { wynik[i] += s - s%i; } } for (int i=1; i<=n; i++) printf("%d ", wynik[i]); puts(""); } |