#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define mid ((l+r)/2) #define siz(x) (int)(x).size() #define BOOST ios_base::sync_with_stdio(0), cin.tie(0) #define deb(x) cout << #x << ": " << x << "\n" typedef long long ll; typedef long double ld; typedef pair<int, int> ii; const int N = 3e5 + 5; map<int, int> cnt; int is[N]; int main(){ BOOST; int n; cin >> n; for(int i=0; i<n; i++){ int x; cin >> x; is[++cnt[x]]++; } for(int i=1; i<=n; i++){ int ans = 0; for(int j=i; j<=n; j += i){ ans += i*is[j]; } cout << ans << " "; } }
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 | #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define mid ((l+r)/2) #define siz(x) (int)(x).size() #define BOOST ios_base::sync_with_stdio(0), cin.tie(0) #define deb(x) cout << #x << ": " << x << "\n" typedef long long ll; typedef long double ld; typedef pair<int, int> ii; const int N = 3e5 + 5; map<int, int> cnt; int is[N]; int main(){ BOOST; int n; cin >> n; for(int i=0; i<n; i++){ int x; cin >> x; is[++cnt[x]]++; } for(int i=1; i<=n; i++){ int ans = 0; for(int j=i; j<=n; j += i){ ans += i*is[j]; } cout << ans << " "; } } |