#include <bits/stdc++.h> #define jd "DEBUG" #define space " " #define endl "\n" #define PRINT(v) std::cout<<#v<<": "<<v<<endl; #define PRINTV(v) std::cout<<#v<<": "; for(auto e : v)cout<<e<<" ";cout<<endl; typedef long long ll; typedef std::vector<int> vi; using namespace std; template <typename T = int> T in(){ T inx; cin>>inx; return inx; } int main(){ cin.tie(0)->sync_with_stdio(0); int n = in<>(); map<int,int> m; for(int i = 0; i < n; i++){ m[in<>()]++; } vi v; for(auto & [key, value] : m){ v.push_back(value); } sort(v.begin(), v.end()); cout<<n<<space; for(int i = 2; i <= n; i++){ ll sum = 0; for(int k = i; k <= n; k+=i){ auto begin = lower_bound(v.begin(), v.end(), k); auto end = upper_bound(v.begin(), v.end(), k+i); int dist = distance(begin, end); end--; if(*end == k+i) dist--; sum+=dist*k; } cout<<sum<<space; } cout<<endl; }
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <bits/stdc++.h> #define jd "DEBUG" #define space " " #define endl "\n" #define PRINT(v) std::cout<<#v<<": "<<v<<endl; #define PRINTV(v) std::cout<<#v<<": "; for(auto e : v)cout<<e<<" ";cout<<endl; typedef long long ll; typedef std::vector<int> vi; using namespace std; template <typename T = int> T in(){ T inx; cin>>inx; return inx; } int main(){ cin.tie(0)->sync_with_stdio(0); int n = in<>(); map<int,int> m; for(int i = 0; i < n; i++){ m[in<>()]++; } vi v; for(auto & [key, value] : m){ v.push_back(value); } sort(v.begin(), v.end()); cout<<n<<space; for(int i = 2; i <= n; i++){ ll sum = 0; for(int k = i; k <= n; k+=i){ auto begin = lower_bound(v.begin(), v.end(), k); auto end = upper_bound(v.begin(), v.end(), k+i); int dist = distance(begin, end); end--; if(*end == k+i) dist--; sum+=dist*k; } cout<<sum<<space; } cout<<endl; } |