Pagini recente » Cod sursa (job #1243107) | Cod sursa (job #1238799) | Cod sursa (job #1838661) | Cod sursa (job #2454975) | Cod sursa (job #3040057)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("radixsort.in");
ofstream out ("radixsort.out");
const int NMAX = 1e7;
const int BITS = 12;
const int MASK = (1LL << BITS) - 1;
const int LGMAX = 32;
int pos[MASK + 1];
int f[MASK + 1];
int a[NMAX], aux[NMAX];
#define octet(x) (x >> bt) & MASK
int main()
{
int n, A, B, C;
in >> n >> A >> B >> C;
a[0] = B;
for (int i=1; i<n; i++)
a[i] = ((long long) A * a[i-1] + B) % C;
for (int bt=0; bt<LGMAX; bt += BITS)
{
memset(f, 0, sizeof(f));
for (int i=0; i<n; i++)
f[octet(a[i])]++;
pos[0] = 0;
for (int i=1; i<=MASK; i++)
pos[i] = pos[i-1] + f[i-1];
for (int i=0; i<n; i++)
aux[pos[octet(a[i])]++] = a[i];
swap(aux, a);
}
for (int i=0; i<n; i+=10)
out << a[i] << ' ';
return 0;
}