Pagini recente » Cod sursa (job #1333338) | Cod sursa (job #538814) | Monitorul de evaluare | Cod sursa (job #362506) | Cod sursa (job #1256579)
#include <cstdio>
#include <iostream>
using namespace std;
#define BASE 255
#define NMax 10000005
#define POW 8
int bucket[BASE];
int a[NMax],c[NMax];
int N;
void radixsort()
{
int exp,i;
while(NMax>(1<<exp))
{
for(i=0;i<=BASE;i++)
bucket[i]=0;
for(i=1;i<=N;i++)
++bucket[(a[i]>>exp)&BASE];
for(i=1;i<=BASE;i++)
bucket[i]+=bucket[i-1];
for(i=N;i>0;i--)
c[bucket[(a[i]>>exp)&BASE]--]= a[i];
for(i=1;i<=N;i++)
a[i]=c[i];
exp=exp+POW;
}
}
int main()
{
int A,B,C,i;
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);
scanf("%d%d%d%d",&N,&A,&B,&C);
a[1]=B;
for(i=2;i<=N;i++) a[i]=(1LL*A*a[i-1]+B)%C;
radixsort();
for(i=1;i<=N;i=i+10)
printf("%d ",a[i]);
}