Pagini recente » Cod sursa (job #3282353) | Cod sursa (job #1052227) | Cod sursa (job #1530079) | Cod sursa (job #2623040) | Cod sursa (job #2216791)
#include <bits/stdc++.h>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
const int NMax = 10000003;
struct number{
unsigned char dig[4];
};
unsigned int n,A,B,C;
unsigned int c[(1 << 8) + 1];
unsigned int a[NMax],b[NMax];
int main()
{
f >> n >> A >> B >> C;
a[1] = B;
for(int i = 2; i <= n; ++i){
a[i] = (unsigned long long)((unsigned long long)A * a[i - 1] + (unsigned long long)B) % (unsigned long long)C;
}
for(int i = 0; i < 4; ++i){
for(int j = 0; j < (1 << 8); ++j){
c[j] = 0;
}
for(int j = 1; j <= n; ++j){
c[(int)(((number*)&a[j])->dig[i])] ++;
}
for(int j = 1; j < (1 << 8); ++j){
c[j] = c[j - 1] + c[j];
}
for(int j = n; j >= 1; --j){
b[c[(int)(((number*)&a[j])->dig[i])]] = a[j];
c[(int)(((number*)&a[j])->dig[i])]--;
}
for(int j = 1; j <= n; ++j){
a[j] = b[j];
}
}
for(int i = 1; i <= n; i += 10){
g << a[i] << ' ';
}
return 0;
}