Pagini recente » Cod sursa (job #3138609) | Cod sursa (job #3131380)
#include <fstream>
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
const int NMAX = 1e7+5;
int n;
int a[NMAX], b[NMAX];
int cnt[256];
void solve()
{
int A, C;
fin >> n >> A >> a[1] >> C;
for(int i = 2; i <= n; i++)
a[i] = (1LL * A * a[i - 1] + a[1]) % C;
for(int buc = 0, shift = 0; buc < 4; buc++, shift += 8)
{
for(int i = 0; i < 256; i++)
cnt[i] = 0;
for(int i = 1; i <= n; i++)
cnt[(a[i] >> shift) & 255]++;
for(int i = 1; i < 256; i++)
cnt[i] += cnt[i - 1];
for(int i = n; i >= 1; i--)
b[cnt[(a[i] >> shift) & 255]--] = a[i];
for(int i = 1; i <= n; i++)
a[i] = b[i];
}
for(int i = 1; i <= n; i += 10)
fout << a[i] << ' ';
fout << '\n';
}
int main()
{
solve();
return 0;
}