Pagini recente » Cod sursa (job #1294257) | Cod sursa (job #862512) | Cod sursa (job #738079) | Cod sursa (job #797519) | Cod sursa (job #1094952)
#include <cstdio>
#include <queue>
using namespace std;
int N, A, B, C;
queue<int> bucket[2][256];
int swc, mod = 0xff;
void read() {
freopen("radixsort.in", "r", stdin);
freopen("radixsort.out", "w", stdout);
scanf("%i%i%i%i", &N, &A, &B, &C);
int prev = B, x;
bucket[swc][prev & mod].push(prev);
for(int i = 1; i < N; i++) {
x = (A * prev + B) % C;
bucket[swc][x & mod].push(x);
prev = x;
}
}
void solve() {
for(int i = 1; i < 4; i++) {
mod <<= 8;
for(int j = 0; j < 256; j++)
while(!bucket[swc][j].empty()) {
int x = bucket[swc][j].front();
bucket[swc][j].pop();
bucket[1 - swc][(x && mod) >> (8 * i)].push(x);
}
swc = 1 - swc;
}
}
void printSolution() {
int k = 1;
for(int i = 0; i < 256; i++) {
while( !bucket[swc][i].empty() ) {
int x = bucket[swc][i].front();
bucket[swc][i].pop();
if( k % 10 == 1 )
printf("%i ", x);
k++;
}
}
}
int main() {
read();
solve();
printSolution();
return 0;
}