Cod sursa(job #2949881)

Utilizator smunteanuMunteanu Stefan Catalin smunteanu Data 2 decembrie 2022 03:08:14
Problema Radix Sort Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

  typedef long long llong;
  const int nmax = 1e7 + 7;

  int n, a, b, c;
  static int v[nmax];

  freopen("radixsort.in", "r", stdin);
  freopen("radixsort.out", "w", stdoutr);
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  cin >> n >> a >> b >> c;

  v[0] = b;

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

  sort(v, v + n);

  for (int i = 0; i < n; i += 10) cout << v[i] << ' ';

}