Pagini recente » Cod sursa (job #2717333) | Cod sursa (job #1876037) | Cod sursa (job #594458) | Cod sursa (job #1156242) | Cod sursa (job #1094957)
#include <cstdio>
#include <deque>
using namespace std;
int N, A, B, C;
deque<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_back(x);
for(int i = 1; i < N; i++) {
x = (A * prev + B) % C;
bucket[swc][x & mod].push_back(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_front();
bucket[1 - swc][(x & mod) >> (8 * i)].push_back(x);
}
swc = 1 - swc;
}
}
void printSolution() {
int k = 1;
for(int i = 0; i < 256; i++) {
for(deque<int> :: iterator j = bucket[swc][i].begin(); j < bucket[swc][i].end(); j++) {
if( !((k - 1) % 10) )
printf("%i ", *j);
k++;
}
}
}
int main() {
read();
solve();
printSolution();
return 0;
}