Pagini recente » Cod sursa (job #563200) | Cod sursa (job #1183001) | Cod sursa (job #260343) | Cod sursa (job #2232729) | Cod sursa (job #1193288)
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
#define NMAX 1000001
#define LL long long
deque < LL > H[10];
LL V[NMAX];
LL A,B,C,N,i,X;
void Radix_sort()
{
LL Y=1,i;
deque < LL > :: iterator it;
for (Y=1;Y<=(LL)(pow(10.0,9))+1;Y*=10)
{
for (i=0;i<=9;++i) H[i].clear();
for (i=1;i<=V[0];++i)
H[(V[i]/Y)%10].push_back(V[i]);
V[0]=0;
for (i=0;i<=9;++i)
for (it=H[i].begin();it!=H[i].end();++it)
V[++V[0]]=*it;
}
}
int main()
{
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);
scanf("%d%d%d%d",&N,&A,&B,&C);
V[0]=1;
V[V[0]]=B;
for (i=2;i<=N;++i)
V[++V[0]]=(A*V[V[0]-1]+B)%C;
Radix_sort();
for (i=1;i<=V[0];i+=10) printf("%d ",V[i]);
printf("\n");
return 0;
}