Pagini recente » Cod sursa (job #1798459) | Cod sursa (job #874494) | Cod sursa (job #3195145) | Cod sursa (job #384404) | Cod sursa (job #2633268)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("radixsort.in");
ofstream fout ("radixsort.out");
unsigned int n, a, b, c, v[10000000];
void Sort (unsigned int bits) {
vector < unsigned int > h[256];
for (unsigned int i = 0; i < n; i ++)
h[(v[i] >> bits) & 255].emplace_back (v[i]);
for (unsigned int i = 1, n = 0; i < 256; i ++)
for (auto it : h[i])
v[n++] = it;
}
int main () {
fin >> n >> a >> b >> c;
v[0] = b;
for(unsigned int i = 1; i < n; i ++)
v[i] = (1LL * a * v[i - 1] + b) % c;
for (unsigned int i = 0; i < 32; i += 8)
Sort (i);
for (unsigned int i = 0; i < n; i += 10)
fout << v[i] << ' ';
return 0;
}