Pagini recente » Cod sursa (job #324439) | Cod sursa (job #136963) | Cod sursa (job #2785791) | Cod sursa (job #1787641) | Cod sursa (job #1773936)
#include "fstream"
using namespace std;
ifstream fin("radix.in");
ofstream fout("radix.out");
const int NMAX = 10000010;
const int DIGITS = 12;
unsigned int a[NMAX];
unsigned int ordered[NMAX];
void radix(long long pow, int N) {
int count[DIGITS + 5];
for(int i = 0 ; i < DIGITS ; i++) {
count[i] = 0;
}
for(int i = 1 ; i <= N ; i++) {
count[(a[i]%pow)/(pow/10)]++;
}
for(int i = 1 ; i < DIGITS; i++) {
count[i] += count[i - 1];
}
// fout << "\n";
// fout.flush();
for(int i = N ; i ; i--) {
// fout << (a[i]%pow)/(pow/10) << "\n";
// fout.flush();
// if(!count[(a[i]%pow)/(pow/10)] || count[(a[i]%pow)/(pow/10)] > N) {
// printf("Wrong count!");
// fflush(stdout);
// while(1) {};
// }
ordered[count[(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";
}