Pagini recente » Cod sursa (job #402811) | Cod sursa (job #1707477) | Cod sursa (job #385265) | Cod sursa (job #2689189) | Cod sursa (job #2136472)
#include <cstdio>
#include <queue>
int N, A, B, C, x, y, ten;
std :: queue<int> bucket[2][256];
int main()
{
freopen("radixsort.in", "r", stdin);
freopen("radixsort.out", "w", stdout);
scanf("%d %d %d %d", &N, &A, &B, &C);
x = B;
bucket[0][x & 255].push(x);
for(int i = 1; i < N; ++i)
{
y = (1LL * x * A + B) % C;
bucket[0][y & 255].push(y);
x = y;
}
for(int i = 0; i < 256; i++)
{
while(!bucket[0][i].empty())
{
x = bucket[0][i].front(); bucket[0][i].pop();
bucket[1][x >> 8 & 255].push(x);
}
}
for(int i = 0; i < 256; i++)
{
while(!bucket[1][i].empty())
{
x = bucket[1][i].front(); bucket[1][i].pop();
bucket[0][x >> 16 & 255].push(x);
}
}
for(int i = 0; i < 256; i++)
{
while(!bucket[0][i].empty())
{
x = bucket[0][i].front(); bucket[0][i].pop();
bucket[1][x >> 24 & 255].push(x);
}
}
for(int i = 0; i < 256; i++)
{
while(!bucket[1][i].empty())
{
if(ten++ % 10 == 0) printf("%d ", bucket[1][i].front());
bucket[1][i].pop();
}
}
return 0;
}