Pagini recente » Cod sursa (job #1177381) | Cod sursa (job #2719935) | Cod sursa (job #1932983) | Cod sursa (job #1780177) | Cod sursa (job #2847434)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
const int dim=1e7+9;
int fv[15],poz[15];
int v[2][dim];
signed main(){
int n,a,b,c;
fin>>n>>a>>b>>c;
v[1][1]=b;
for(int i=2;i<=n;i++){
v[1][i]=(a*v[1][i-1]+b)%c;
}
int elim=1,cnt=2,t=11;
while(t--){
fill(fv,fv+10,0);
for(int i=1;i<=n;i++){
int nr=v[(cnt-1)%2][i]/elim;
fv[nr%10]++;
v[cnt%2][i]=0;
}
poz[0]=1;
for(int i=1;i<=9;i++){
poz[i]=poz[i-1]+fv[i-1];
}
for(int i=1;i<=n;i++){
int nr=v[(cnt-1)%2][i]/elim;
v[cnt%2][poz[nr%10]]=v[(cnt-1)%2][i];
poz[nr%10]++;
}
cnt++,elim*=10;
}
for(int i=1;i<=n;i+=10){
fout<<v[cnt%2][i]<<' ';
}
}