Pagini recente » Cod sursa (job #1166985) | Cod sursa (job #2110230) | Cod sursa (job #920076) | Cod sursa (job #1464144) | Cod sursa (job #2134427)
#include <bits/stdc++.h>
using namespace std;
int64_t n, v[10000005];
vector<int64_t> buckets[10];
void list_to_buckets(int64_t it)
{
for (int64_t i = 0; i < 10; ++i)
buckets[i].clear();
for (int64_t i = 1; i <= n; ++i){
int64_t dig = v[i]%it;
dig /= (it/10);
buckets[dig].push_back(v[i]);
}
}
void buckets_to_list()
{
int p = 0;
for (int i = 0; i < 10; ++i)
for (vector<int64_t>::iterator it = buckets[i].begin(); it != buckets[i].end(); ++it)
v[++p] = *it;
}
int main()
{
ifstream fin ("radixsort.in");
ofstream fout ("radixsort.out");
fin >> n;
int64_t a, b, c;
fin >> a >> b >> c;
v[1] = b;
for (int64_t i = 2; i <= n; ++i)
v[i] = (a*v[i-1]+b)%c;
int64_t it = 10;
for (int64_t i = 1; i <= 10; ++i){
list_to_buckets(it);
buckets_to_list();
it *= 10;
}
for (int64_t i = 1; i <= n; i += 10)
fout << v[i] << " ";
return 0;
}