int a[maxn], cnt[maxn], ops[maxn], ans[maxn], bucket[maxn]; vector<int> v0, v1, v2;
voidbucket_sort(vector<int> &v){ memset(bucket, 0, sizeof(bucket)); for (int i = 0; i < v.size(); i++) bucket[v[i]]++; v.clear(); for (int i = 0; i < maxn; i++) for (int j = 0; j < bucket[i]; j++) v.push_back(i); }
intmain(){ #ifndef LOCAL freopen("equal.in", "r", stdin); freopen("equal.out", "w", stdout); #endif int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); cnt[a[i]]++; } for (int i = 1; i < maxn; i++){ if (cnt[i]){ bool flag = false; for (int j = 2; i * j < maxn; j++) { if (cnt[i * j]) { flag = true; break; } } if (flag) v0.push_back(cnt[i]); else v1.push_back(cnt[i]); } } int vn = v0.size() + v1.size(); bucket_sort(v0); bucket_sort(v1); for (int i = 0; i < v0.size(); i++) v2.push_back(v0[i]); for (int i = 2; i < v1.size(); i++) v2.push_back(v1[i]); bucket_sort(v2);
ops[vn] = 0; int x = 0, y = 0; if (v1.size() >= 2) y+=v1[0] + v1[1]; else y = 2 * n; for (int k = 1; k < vn; k++) { if (k <= v0.size()) x += v0[k - 1]; else x = 2 * n; if (k > 1) y+=v2[k - 2]; // printf("x = %d, y = %d, k = %d\n", x, y, k); ops[vn - k] = min(x, y); } for (int i = 1; i <= vn; i++){ ans[ops[i]] = i; } for (int i = 1; i <= n; i++){ if (ans[i] == 0) ans[i] = ans[i-1]; } for (int i = 0; i <= n; i++) printf("%d%c", ans[i], (i == n?10:32));