Pagini recente » Cod sursa (job #1985145) | Cod sursa (job #1606340) | Cod sursa (job #1239222) | Cod sursa (job #2270065) | Cod sursa (job #2241547)
#include <bits/stdc++.h>
using namespace std;
int v[10000001], n, A, B, C;
int ordonat[10000001];
int countingSort[1 << 16];
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
void citire(){
fin >> n >> A >> B >> C;
v[1] = B;
for(int i = 2; i <= n; ++i){
v[i] = (1LL * A * v[i-1] + B) % C;
}
}
void radixSort(int bucketSize, int whichBucket){
int constant = 1 << bucketSize, mask = (1 << bucketSize) - 1;
for(int i = 0; i < constant; ++i) countingSort[i] = 0;
for(int i = 1; i <= n; ++i){
int current_value = (v[i] >> (bucketSize * whichBucket)) & mask;
countingSort[current_value] ++;
}
for(int i = 1; i < constant; ++i) countingSort[i] += countingSort[i - 1];
for(int i = n; i >= 1; --i){
int current_value = (v[i] >> (bucketSize * whichBucket)) & mask;
ordonat[countingSort[current_value]] = v[i];
countingSort[current_value]--;
}
for(int i = 1; i <= n; ++i) v[i] = ordonat[i];
}
void afisare(){
for(int i = 1; i <= n; i += 10) fout << v[i] << " ";
}
int main()
{
citire();
for(int i = 0; i < 2; ++i) radixSort(16, i);
afisare();
return 0;
}