#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef vector<int> vi; #define pb push_back #define fi first #define se second #define rep(i,b,e) for(int i=(b); i<(e); i++) #define each(a,x) for(auto &a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<int,int> cnt; vi tab; int a; rep(i,0,n){ cin>>a; cnt[a]++;} for(auto &&[a,b] : cnt) tab.pb(b); sort(all(tab)); reverse(all(tab)); for(int k=1; k<=n; ++k) { ll res=0; rep(i,0,n) { res+=tab[i]/k*k; if(tab[i]/k==0) break;} cout<<res<<" ";} 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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef vector<int> vi; #define pb push_back #define fi first #define se second #define rep(i,b,e) for(int i=(b); i<(e); i++) #define each(a,x) for(auto &a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<int,int> cnt; vi tab; int a; rep(i,0,n){ cin>>a; cnt[a]++;} for(auto &&[a,b] : cnt) tab.pb(b); sort(all(tab)); reverse(all(tab)); for(int k=1; k<=n; ++k) { ll res=0; rep(i,0,n) { res+=tab[i]/k*k; if(tab[i]/k==0) break;} cout<<res<<" ";} return 0; } |