Pagini recente » Cod sursa (job #1833271) | Cod sursa (job #801598) | Cod sursa (job #1809880) | Cod sursa (job #2834408) | Cod sursa (job #1732910)
#include <iostream>
#include <fstream>
using namespace std;
const int nmax = 10000001;
int a[nmax];
int temp[nmax];
int counts[257];
int n;
int A,B,C;
int i;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
void radixSort();
int main()
{
fin >> n;
fin >> A >> B >> C;
a[0] = B%C;
for(int i=1; i<n; i++)
{
a[i] = (1LL * A * a[i-1] % C + B)%C;
}
radixSort();
for(int i=0; i<n; i+=10)
{
fout << a[i] << " ";
}
fin.close();
fout.close();
return 0;
}
void radixSort()
{
for(int digit = 0; digit <4; digit++)
{
for( i=0;i<256; i++)
counts[i] =0;
for(i=0; i<n; i++)
counts[(a[i]>>(digit*8))&255]++;
for(i=1; i<256; i++)
counts[i] +=counts[i-1];
for(i=n-1; i>=0; i--)
{
temp[counts[(a[i]>>(digit*8))&255]-1] = a[i];
counts[(a[i]>>(digit*8))&255]--;
}
for(i=0;i<n;i++)
a[i] = temp[i];
}
}