Pagini recente » Cod sursa (job #2114979) | Cod sursa (job #2535917) | Cod sursa (job #838842) | Cod sursa (job #2028356) | Cod sursa (job #2361599)
#include <bits/stdc++.h>
#define NMAX 10000005
using namespace std;
ifstream fin("radixsort.in");
int v[NMAX], aux[NMAX];
void countSort(int V[], int lg, int EXP){
int xCount[12];
memset(xCount, 0, sizeof(xCount));
for(int i = 1; i <= lg; ++i)
xCount[(V[i] / EXP) % 10]++;
for(int i = 1; i <= 9; ++i)
xCount[i] += xCount[i - 1];
for(int i = lg; i >= 1; --i){
aux[xCount[(V[i] / EXP) % 10]] = V[i];
xCount[(V[i] / EXP) % 10]--;
}
for(int i = 1; i <= lg; ++i)
V[i] = aux[i];
}
void radixSort(int vec[], int lg, int maxx){
for(int EXP = 1; maxx / EXP > 0; EXP *= 10)
countSort(vec, lg, EXP);
}
int main()
{
freopen("radixsort.out", "w", stdout);
long long n, a, b, c;
fin >> n >> a >> b >> c;
int maxx = b;
v[1] = b;
for(int i = 2; i <= n; ++i)
v[i] = (a * v[i - 1] + b) % c,
maxx = max(maxx, v[i]);
radixSort(v, n, maxx);
for(int i = 1; i <= n; i += 10)
printf("%d ", v[i]);
return 0;
}