Pagini recente » Cod sursa (job #1394436) | Cod sursa (job #2144241) | Cod sursa (job #1446177) | Cod sursa (job #792821) | Cod sursa (job #2269502)
#include<fstream>
#include<cstring>
using namespace std;
ifstream cin("radixsort.in");
ofstream cout("radixsort.out");
int N;
unsigned long long A,B,C;
unsigned V[10000005],Count[256],Rez[10000005],Index[256];
unsigned byte(unsigned x,int i){
return (x>>(i*8))&255;
}
int main(){
cin>>N>>A>>B>>C;
V[1]=B%C;
for(int i=2;i<=N;++i)
V[i]=(A*V[i-1]+B)%C;
for(int i=0;i<4;++i){
for(int j=1;j<=N;++j)
++Count[byte(V[j],i)];
Index[0]=1;
for(int j=1;j<256;++j)
Index[j]=Index[j-1]+Count[j-1];
for(int j=1;j<=N;++j)
Rez[Index[byte(V[j],i)]++]=V[j];
for(int j=1;j<=N;j++)
V[j]=Rez[j];
memset(Count,0,sizeof(Count));
}
for(int i=1;i<=N;i+=10)
cout<<V[i]<<' ';
}