Pagini recente » Cod sursa (job #2275880) | Cod sursa (job #2286740) | Cod sursa (job #1519045) | Cod sursa (job #2110843) | Cod sursa (job #1094946)
#include <cstdio>
#include <queue>
using namespace std;
int N, A, B, C;
queue<int> bucket[2][2];
int swc;
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 & 1].push(prev);
for(int i = 1; i < N; i++) {
x = (A * prev + B) % C;
bucket[swc][x & 1].push(x);
prev = x;
}
}
void solve() {
for(int i = 1; i < 32; i++) {
for(int j = 0; j < 2; j++)
while(!bucket[swc][j].empty()) {
int x = bucket[swc][j].front();
bucket[swc][j].pop();
bucket[1 - swc][(x & (1 << i)) ? 1 : 0].push(x);
}
swc = 1 - swc;
}
}
void printSolution() {
int k = 1;
for(int i = 0; i < 2; 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;
}