Pagini recente » Cod sursa (job #845928) | Cod sursa (job #2208667) | Cod sursa (job #2851513) | Cod sursa (job #304359) | Cod sursa (job #1668337)
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
long n,d,b,c,x;
queue <int> a;
queue <int> l[257];
int main()
{
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);
scanf("%d %d %d %d",&n,&d,&b,&c);
a.push(b);
x=b;
for(int i=1; i<n; i++)
{
//cout<<x<<" ";
x=(x*d+b)%c;
a.push(x);
}
//cout<<endl;
for(int nrn=0; nrn<4; nrn++)
{
int z;
while(!a.empty())
{
x=a.front();
a.pop();
/*z=256*nrn;
if(z==0)
z=1;
l[(x/z)%256].push(x);*/
z=x;
//z=z>>1;
z=z<<(3-nrn)*8;
z=z>>24;
//cout<<z<<" ";
if(z<0)
z*=-1;
l[z].push(x);
}
for(int i=0; i<256; i++)
{
while(!l[i].empty())
{
a.push(l[i].front());
l[i].pop();
}
}
}
int i=0;
while(!a.empty())
{
if(i%10==0)
cout<<a.front()<<" ";
i++;
a.pop();
}
return 0;
}