Pagini recente » Cod sursa (job #245352) | Cod sursa (job #1548855) | Cod sursa (job #475286) | Cod sursa (job #2848552) | Cod sursa (job #3327701)
#include<bits/stdc++.h>
using namespace std;
const int MAXBITS=32;
const int BITS=8;
const int MAXN=1e7;
const int MAXM=256;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int v[MAXN+1],tmp[MAXN+1];
int f[MAXM];
int main() {
int n,a,b,c;
fin>>n>>a>>b>>c;
v[0]=b;
for(int i=1; i<n; i++) {
v[i]=((long long)a*v[i-1]+b)%c;
}
int nr;
for(int j=0; j<MAXBITS/BITS; j++) {
for(int i=0; i<n; i++) {
f[(v[i]>>(j*BITS))&(MAXM-1)]++;
}
for(int i=1; i<MAXM; i++) {
f[i]+=f[i-1];
}
for(int i=n-1; i>=0; i--) {
tmp[--f[(v[i]>>(j*BITS))&(MAXM-1)]]=v[i];
}
for(int i=0; i<n; i++) {
v[i]=tmp[i];
}
for(int i=0; i<MAXM; i++) {
f[i]=0;
}
}
for(int i=0; i<n; i+=10) {
fout<<v[i]<<' ';
}
return 0;
}