Pagini recente » Cod sursa (job #129970) | Cod sursa (job #874909) | Cod sursa (job #735984) | Cod sursa (job #3250053) | Cod sursa (job #2224837)
#include <bits/stdc++.h>
using namespace std;
vector <int> v;
vector <int> countingSort [1 << 16];
int main() {
ifstream fin ("radixsort.in");
ofstream fout ("radixsort.out");
int n, a, b, c, mask = (1 << 16) - 1;
fin >> n >> a >> b >> c;
v.push_back(b);
for (int i = 2; i <= n; ++i) {
int newValue = static_cast<int>((1LL * a * v.back() + b) % c);
v.push_back(newValue);
}
for (auto x : v) {
int currentPosition = x & mask;
countingSort[currentPosition].push_back(x);
}
v.clear();
for (int i = 0; i < (1 << 16); ++i) {
for (auto x : countingSort[i]) {
v.push_back(x);
}
countingSort[i].clear();
}
mask <<= 16;
for (auto x : v) {
int currentPosition = x & mask;
countingSort[currentPosition].push_back(x);
}
v.clear();
for (int i = 0; i < (1 << 16); ++i) {
for (auto x : countingSort[i]) {
v.push_back(x);
}
countingSort[i].clear();
}
for (int i = 0; i < n; i += 10) {
fout << v[i] << ' ';
}
return 0;
}