#include <iostream>
#include <algorithm>
int t1[10000000];
int t2[10000000];
int n,x,y;
int wynik;
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=0; i<n; i++)
cin>>t1[i];
sort(t1,t1+n);
x=t1[0];
for(int i=0; i<n; i++)
{
if(t1[i]==x)t2[y]++;
if(t1[i]!=x)
{
x=t1[i];
y++;
t2[y]++;
}
}
for(int i=1; i<=n; i++)
{
for(int j=0; j<=y; j++)
{
if(t2[j]>=i && t2[j]%i==0) wynik+=t2[j];
else if(t2[j]>=i)wynik+=i*(t2[j]/i);
}
cout<<wynik<<" ";
wynik=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 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <iostream> #include <algorithm> int t1[10000000]; int t2[10000000]; int n,x,y; int wynik; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; for(int i=0; i<n; i++) cin>>t1[i]; sort(t1,t1+n); x=t1[0]; for(int i=0; i<n; i++) { if(t1[i]==x)t2[y]++; if(t1[i]!=x) { x=t1[i]; y++; t2[y]++; } } for(int i=1; i<=n; i++) { for(int j=0; j<=y; j++) { if(t2[j]>=i && t2[j]%i==0) wynik+=t2[j]; else if(t2[j]>=i)wynik+=i*(t2[j]/i); } cout<<wynik<<" "; wynik=0; } } |
English