Pagini recente » Cod sursa (job #263921) | Cod sursa (job #1129488) | Cod sursa (job #1649831) | Cod sursa (job #3158547) | Cod sursa (job #1842898)
#include <cstdio>
#define NMAX 10000003
#define grupa(nr, step) ((nr >> step) & 1)
using namespace std;
int s[2][2][NMAX];
int ls[2][2];
int n, a, b, c;
int pc = 0, lc = 0, *vc, indc = -1;
int mc = 1, mp;
inline void next(int& val)
{
while(pc == lc)
{
vc = s[mp][++indc];
lc = ls[mp][indc];
pc = 0;
}
val = vc[pc++];
}
int main()
{
int i, gr = 0, aux, prev;
freopen("radixsort.in", "r", stdin);
freopen("radixsort.out", "w", stdout);
scanf("%d%d%d%d", &n, &a, &b, &c);
prev = b;
s[0][prev & 1][ls[0][prev & 1]++] = prev;
for(i = 1; i < n; i++)
{
aux = ((1LL * a * prev) % c + b) % c;
s[0][aux & 1][ls[0][aux & 1]++] = aux;
prev = aux;
}
for(gr = 1; gr != 33; gr++)
{
for(i = 0; i < 2; i++) ls[mc][i] = 0;
for(i = 0; i < n; i++)
{
next(aux);
s[mc][grupa(aux, gr)][ls[mc][grupa(aux, gr)]++] = aux;
}
pc = 0; lc = 0; indc = -1;
mc = mp;
mp = (mp == 1) ? 0 : 1;
}
mp = mc;
for(i = 0; i < n; i++)
{
next(aux);
if(i % 10 == 0) printf("%d ", aux);
}
return 0;
}