Pagini recente » Monitorul de evaluare | Cod sursa (job #2149247) | Cod sursa (job #2684944) | Cod sursa (job #1618084) | Cod sursa (job #2410068)
#include <bits/stdc++.h>
using namespace std;
int getByte(int x, int i) {
return (x>>(8*i))&0xff;
}
const int MAXN = 1e7 + 10;
queue< int > radix[256];
int v[MAXN];
int main() {
#ifdef BLAT
freopen("input", "r", stdin);
#else
freopen("radixsort.in", "r", stdin);
freopen("radixsort.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, a, b, c;
cin >> n >> a >> b >> c;
v[1] = b;
for(int i = 2; i <= n; ++i) {
v[i] = (1ll*a*v[i-1] + 1ll*b) % c;
}
for(int i = 0; i < 4; ++i) {
for(int j = 1; j <= n; ++j) {
radix[getByte(v[j], i)].push(v[j]);
}
int ind = 0;
for(int j = 0; j < 256; ++j) {
while(radix[j].size()) {
v[++ind] = radix[j].front();
radix[j].pop();
}
}
assert(ind == n);
}
for(int i = 1; i <= n; i += 10) cout << v[i] << ' ';
return 0;
}