Pagini recente » Cod sursa (job #994418) | Cod sursa (job #2047413) | Cod sursa (job #677465) | Cod sursa (job #2473880) | Cod sursa (job #1475581)
#include <cstdio>
#include <cstring>
const int NMAX = 10000505;
const int FBYTE = (1 << 8) - 1;
const int LMAX = (1 << 8) + 1;
int n, a, b, c, A[2][NMAX];
int getByte(int idx, int val) {
return (val >> (idx * 8)) & FBYTE;
}
void read() {
scanf("%d%d%d%d", &n, &a, &b, &c);
A[0][1] = b;
for (int i = 2; i <= n; i++) {
A[0][i] = (1LL * a * A[0][i - 1] + b) % c;
}
}
void radixSort(int left, int right, int byte) {
if (byte == 4) {
return ;
}
int cnt[LMAX] = {0};
for (int i = left; i <= right; i++) {
cnt[getByte(byte, A[byte & 1][i])]++;
}
for (int i = 1; i <= FBYTE; i++) {
cnt[i] += cnt[i - 1];
}
cnt[LMAX - 1] = cnt[FBYTE];
for (int i = left; i <= right; i++) {
int val = getByte(byte, A[byte & 1][i]);
A[1 - (byte & 1)][left + cnt[val] - 1] = A[byte & 1][i];
cnt[val]--;
}
radixSort(left, right, byte + 1);
}
int main() {
freopen("radixsort.in", "r", stdin);
freopen("radixsort.out", "w", stdout);
read();
radixSort(1, n, 0);
for (int i = 1; i <= n; i += 10)
printf("%d ", A[1][i]);
printf("\n");
return 0;
}