Pagini recente » Cod sursa (job #8024) | Cod sursa (job #50030) | Cod sursa (job #1832526) | Cod sursa (job #2960851) | Cod sursa (job #1401500)
#include <stdio.h>
#include <vector>
#include <algorithm>
#define NMax 10000006
using namespace std;
int n,a,b,c,x[NMax],out[NMax],countV[1<<8];
long long val;
void radix_sort(int shift,int bit)
{
int mash = (1<<bit)-1;
for(int i=1;i<=(1<<bit);++i)countV[i] = 0;
for(int i=1;i<=n;++i)
{
countV[ (x[i]>>shift)&mash ]++;
}
for(int i=1;i<=mash;++i)
{
countV[i] += countV[i-1];
}
for(int i=n;i>=1;--i)
{
out[ countV[ (x[i]>>shift)&mash ] ] = x[i];
countV[ (x[i]>>shift)&mash ]--;
}
for(int i=1;i<=n;++i)x[i] = out[i];
}
int main()
{
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);
scanf("%d %d %d %d",&n,&a,&b,&c);
x[1] = b;
for(int i=2;i<=n;++i)
{
val = (a * x[i-1] + b) % c;
x[i] = val;
}
for(int i=0;i<=24;i+=8)radix_sort(i,8);
for(int i=1;i<=n;i+=10)printf("%d ",x[i]);
return 0;
}