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