Pagini recente » Cod sursa (job #136960) | Cod sursa (job #752679) | Cod sursa (job #1839239) | Cod sursa (job #1653889) | Cod sursa (job #1774214)
#include "fstream"
using namespace std;
ifstream fin("radix.in");
ofstream fout("radix.out");
const int NMAX = 10000015;
const int DIGITS = 12;
unsigned int a[NMAX];
unsigned int ordered[NMAX];
unsigned int cnt[DIGITS + 5];
void radix(long long pow, int N) {
for(int i = 0 ; i < DIGITS ; i++) {
cnt[i] = 0;
}
for(int i = 1 ; i <= N ; i++) {
cnt[(a[i]%pow)/(pow/10)]++;
}
for(int i = 1 ; i < DIGITS; i++) {
cnt[i] += cnt[i - 1];
}
// fout << "\n";
// fout.flush();
for(int i = N ; i ; i--) {
// fout << (a[i]%pow)/(pow/10) << "\n";
// fout.flush();
if(!cnt[(a[i]%pow)/(pow/10)]) {
printf("Wrong cnt!");
fflush(stdout);
while(1) {};
}
ordered[cnt[(a[i]%pow)/(pow/10)]--] = a[i];
}
// for(int i = 1 ; i <= N; i++) {
// fout << ordered[i] << " ";
// }
// fout << "\n";
// fout.flush();
for(int i = 1 ; i <= N ; i++) {
a[i] = ordered[i];
}
}
int main() {
int N;
long long A, B, C;
fin >> N >> A >> B >> C;
a[1] = B;
for(int i = 2 ; i <= N ; i++) {
a[i] = ((long long)A * a[i - 1] + B) % C;
}
for(long long pow = 10 ; pow <= 10000000000 ; pow *= 10) {
// for(int i = 1 ; i <= N ; i++) {
// fout << a[i] << " ";
// }
// fout << "\n";
radix(pow, N);
}
for(int i = 1 ; i <= N ; i += 10) {
fout << a[i] << " ";
}
fout << "\n";
}