Cod sursa(job #1974404)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 27 aprilie 2017 15:53:35
Problema Radix Sort Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;
long long N, A, B, C;
const int MASK = 255;
vector<int> v;

void radix(int k)
{
    vector<int> rad[MASK + 1];
    for(auto it : v)
        rad[MASK & (it >> k)].push_back(it);
    int crt = 0;
    for(int i = 0; i <= MASK; ++i)
        for(auto it : rad[i])
            v[crt++] = it;
}

int main()
{
    freopen("radixsort.in", "r", stdin);
    freopen("radixsort.out", "w", stdout);

    scanf("%lld%lld%lld%lld", &N, &A, &B, &C);
    v.push_back(B);
    for(int i = 1; i < N; ++i)
        v.push_back( (1LL * A * v[i-1] + B) % C );

    for(int i = 0; i < 4; ++i)
        radix(8 * i);

    for(int i = 1; i <= N; i += 10)
        printf("%d ", v[i - 1]);

    return 0;
}