Pagini recente » Cod sursa (job #1517317) | Cod sursa (job #3198091) | Cod sursa (job #552468) | Cod sursa (job #2953067) | Cod sursa (job #1110980)
#include<cstdio>
using namespace std;
const int nmax = 10000005;
const int mask = (1<<8)-1;
int n,a,b,c,i,k,shift,v[nmax],w[nmax],g[mask+5];
int main()
{
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);
scanf("%d%d%d%d",&n,&a,&b,&c); v[1]=b;
for(i=2;i<=n;i++) v[i]=(a*v[i-1]+b)%c;
for(shift=0;shift<32;shift+=8)
{
for(i=1;i<=n;i++)
{
k=(v[i]>>shift)&mask;
g[k]++;
}
for(i=1;i<=mask;i++) g[i]+=g[i-1];
for(i=n;i;i--)
{
k=(v[i]>>shift)&mask;
w[g[k]--]=v[i];
}
for(i=1;i<=n;i++) v[i]=w[i];
for(i=0;i<=mask;i++) g[i]=0;
}
for(i=1;i<=n;i+=10) printf("%d ",v[i]);
return 0;
}