Pagini recente » Cod sursa (job #2215320) | Cod sursa (job #1963677) | Cod sursa (job #2973800) | Cod sursa (job #1282575) | Cod sursa (job #2980967)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
#ifdef LOCAL
ifstream fin("input.txt");
#define fout cout
#else
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
#define endl '\n'
#endif
int n, A, B, C;
vector<queue<uint>> a(512);
void solve() {
for (int i = 1, x = B; i <= n; i++) {
a[x & 0xff].push(x);
x = (1ll * A * x + B) % C;
}
for (int i = 1; i < 4; i++) {
auto aux = a;
for (auto &qe : a) {
qe = {};
}
for (auto &qe : aux) {
while (!qe.empty()) {
uint x = qe.front();
qe.pop();
a[x & (0xff << (i * 8))].push(x);
}
}
}
int i = 10;
for (auto &qe : a) {
while (!qe.empty()) {
if (i++ == 10) {
fout << qe.front() << ' ';
i = 1;
}
qe.pop();
}
}
}
int main() {
fin >> n >> A >> B >> C;
solve();
return 0;
}