Pagini recente » Cod sursa (job #2113624) | Cod sursa (job #2385431) | Cod sursa (job #1361112) | Cod sursa (job #2315796) | Cod sursa (job #1210690)
#include <fstream>
#include <stack>
#define B 4
#define biti 8
#define DIM 10000010
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
//2 16
//4 8
int v[DIM], w[DIM];
int f[1<<biti];
int n, a, b, c, i, p, k;
int main(){
fin>>n>>a>>b>>c;
v[1] = b;
for (i=2;i<=n;i++)
v[i] = (int)((1LL * a * v[i-1] + b) % c);
for (p = 0; p<B; p++) {
for (i=1;i<=n;i++)
f[ (v[i]>>(p*biti)) & ((1<<biti)-1) ]++;
for (i=1;i<=(1<<biti)-1;i++)
f[i] += f[i-1];
for (i=n;i>=1;i--) {
w[ f[ (v[i]>>(p*biti)) & ((1<<biti)-1) ] ] = v[i];
f[ (v[i]>>(p*biti)) & ((1<<biti)-1) ] --;
}
for (i=1;i<=n;i++)
v[i] = w[i];
}
for (i=1;i<=n;i+=10)
fout<<v[i]<<" ";
return 0;
}