Pagini recente » Cod sursa (job #1389236) | Cod sursa (job #3005458) | Cod sursa (job #306305) | Cod sursa (job #540126) | Cod sursa (job #1904657)
#include <bits/stdc++.h>
#define NMAX 10000005
#define BUCKETS 257
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int V[NMAX + 1];
deque < int > B[BUCKETS];
void radixsort(const int &N){
for(int x = 0; x < 4; x++){
for(int j = 1; j <= N; j++){
int y = (V[j] >> (8 * x)) & 255;
B[y].push_back(V[j]);
}
for(int n = 0,i = 0; i < 256; i++)
while(!B[i].empty()){
V[++n] = B[i].front();
B[i].pop_front();
}
}
}
int main()
{
ios :: sync_with_stdio(false);
int N,A,B,C;
fin >> N >> A >> B >> C;
V[1] = B;
for(int i = 2; i <= N; i++)
V[i] = (A * V[i - 1] * 1LL + B) % C;
radixsort(N);
for(int i = 1; i <= N; i+= 10)
fout << V[i] << " ";
return 0;
}