Pagini recente » Cod sursa (job #1233626) | Cod sursa (job #1543453) | Cod sursa (job #2550720) | Cod sursa (job #1528655) | Cod sursa (job #2386340)
#include <fstream>
#include <queue>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int n,a,b,c,v[10000001],i,j,nr;
queue <int> q[4096];
int main()
{
ios::sync_with_stdio(false);
f>>n>>a>>b>>c;
v[1]=b;
for(i=2; i<=n; i++)v[i]=(1LL*v[i-1]*a+b)%c;
for(j=0; j<=24; j+=8)
{
for(i=1; i<=n; i++)q[(v[i]>>j)&255].push(v[i]);
nr=0;
for(i=0; i<=255 && nr<n; i++)
while(!q[i].empty())
{
v[++nr]=q[i].front();
q[i].pop();
}
}
for(i=1; i<=n; i=i+10)g<<v[i]<<' ';
return 0;
}