Pagini recente » Cod sursa (job #1150876) | Cod sursa (job #1489314) | Rating Penzes Noemi (noemi_pz4) | Cod sursa (job #1085853) | Cod sursa (job #1520391)
#define filename "radixsort"
#define REP(a,b) for(int a=0; a<(b); ++a)
#define REP2(a, b) for(int a=1; a<=(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define BCK(a,b,c) for(int a=(b)-1; a>=(c); --a)
#define BCK2(a,b,c) for(int a=(b); a>(c); --a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define FILL(x,y) memset(x,y,sizeof(x))
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define x first
#define y second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define l(n) (n<<1)
#define r(n) ((n<<1)+1)
#define f(n) (n>>1)
#define lsb(a) (a&-a)
#define get_byte(x) ((x>>(byte*8)) & 0xFF)
#include<vector>
#include<stack>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
#ifndef ONLINE_JUDGE
#include<fstream>
ifstream cin(filename".in");
ofstream cout(filename".out");
#else
#include<iostream>
#endif
const int NMAX = 10000005;
const int dx[] = {0, 1, 0, -1}; //1,1,-1,1};
const int dy[] = {-1, 0, 1, 0}; //1,-1,1,-1};
typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef pair<K, K> PKK;
typedef vector<int> VI;
int A[NMAX], B[NMAX];
int a,b,c,n;
void sort(int A[], int B[], int byte)
{
int cnt[1<<8];
memset(cnt, 0, sizeof(cnt));
for(int i=0; i<n; ++i)
cnt[get_byte(A[i])+1]++;
for(int i=2; i<=(1<<8); ++i)
cnt[i]+=cnt[i-1];
cnt[0]=0;
for(int i=0; i<n; ++i)
B[cnt[get_byte(A[i])]++]=A[i];
}
int main()
{
cin>>n>>a>>b>>c;
A[0]=b;
for(int i=1; i<n; ++i)
A[i]=(1LL*a*A[i-1] + b)%c;
for(int i=0; i<8; ++i)
{
if((i%2)==0)
sort(A, B, i);
else
sort(B, A, i);
}
for(int i=0; i<n; i+=10)
cout<<A[i]<<" ";
}