Cod sursa(job #3354001)

Utilizator radu._.21Radu Pelea radu._.21 Data 13 mai 2026 12:42:26
Problema Radix Sort Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("radixsort.in");
ofstream fout("radixsort.out");

int n, a, b, c;
int v[10000005];
int aux[10000005];

void radixsort() {
    int *src = v;
    int *dst = aux;
    for (int shift = 0; shift < 32; shift += 8) {
        int count[256] = {0};

        for (int i = 1; i <= n; i++) {
            int cifra = (src[i] >> shift) & 255;
            count[cifra]++;
        }
        for (int i = 1; i < 256; i++) {
            count[i] += count[i - 1];
        }

        for (int i = n; i >= 1; i--) {
            int cifra = (src[i] >> shift) & 255;
            dst[count[cifra]] = src[i];
            count[cifra]--;
        }

        swap(src, dst);
    }

}

int main() {

    fin>>n>>a>>b>>c;

    v[1] = b;
    for (int i =2; i<= n; i++) {
        v[i] = (1LL *a *v[i-1]+ b) % c;
    }

    radixsort();

    for (int i =1;i <=n;i+=10) {
        fout << v[i] << " ";
    }

    return 0;
}