Pagini recente » Cod sursa (job #1838374) | Cod sursa (job #2157582) | Cod sursa (job #656725) | Cod sursa (job #1187570) | Cod sursa (job #2847428)
#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;
while(true){
bool ok=false;
fill(fv,fv+10,0);
for(int i=1;i<=n;i++){
int nr=v[(cnt-1)%2][i]/elim;
if(nr){
ok=true;
}
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]++;
}
if(!ok){
break;
}
cnt++,elim*=10;
}
for(int i=1;i<=n;i+=10){
fout<<v[cnt%2][i]<<' ';
}
}