Pagini recente » Clasament miautotcevreau | Cod sursa (job #816397) | Cod sursa (job #451598) | Cod sursa (job #2986763) | Cod sursa (job #2856866)
#include <bits/stdc++.h>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int v[10000005];
int a,b,c,n;
int digit[257];
int maxx;
long long pw=1;
int vt[10000005];
void solve() {
f >> n >> a >> b >> c;
v[0]= maxx = b;
for (int i=1;i<n;i++) {
v[i] = (1LL*a*v[i-1]+b)%c;
maxx = max(maxx,v[i]);
}
while (maxx) {
pw*=256; maxx/=256;
fill(digit,digit+256,0);
for (int i=0;i<n;i++) {
digit[(v[i]%pw)/(pw/256)]++;
}
for (int i=1;i<256;i++) {
digit[i] += digit[i-1];
}
for (int i=255;i>=1;i--) {
digit[i] = digit[i-1];
}
digit[0] = 0;
for (int i=0;i<n;i++) {
vt[digit[(v[i]%pw)/(pw/256)]] = v[i];
digit[(v[i]%pw)/(pw/256)]++;
}
for (int i=0;i<n;i++) {
v[i] = vt[i];
}
}
for (int i=0;i<n;i+=10) {
g << v[i] << " ";
}
}
int main()
{
solve();
return 0;
}