Pagini recente » Cod sursa (job #2018473) | Cod sursa (job #537969) | Cod sursa (job #2953368) | Cod sursa (job #821333) | Cod sursa (job #2224885)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int MAXBIT = 1 << 17;
vector<int> bucket1[MAXBIT], bucket2[MAXBIT];
int main()
{
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int n, a, b, c;
fin >> n >> a >> b >> c;
long long mask = (1LL << 16) - 1;
bucket1[b & mask].push_back(b);
int lastval = b;
for(int i = 1; i <= n; ++i){
int val = (a * lastval + b) % c;
bucket1[val & mask].push_back(val);
lastval = val;
}
mask <<= 16;
for(int i = 0; i <= 1 << 16; ++i)
for(int j = 0; j < bucket1[i].size(); ++j){
int pos = bucket1[i][j] & mask;
pos >>= 16;
bucket2[pos].push_back(bucket1[i][j]);
}
int index = 1;
for(int i = 0; i <= 1 << 16; ++i){
for(int j = 0; j < bucket2[i].size(); ++j){
if(index % 10 == 1)
fout << bucket2[i][j] << " ";
index++;
}
}
return 0;
}