Pagini recente » Cod sursa (job #1201991) | Agm 2018 Runda 1 | Cod sursa (job #1618870) | Cod sursa (job #560858) | Cod sursa (job #1934663)
#include <bits/stdc++.h>
#define nm 10000010
#define buckets 257
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int v[nm],n,a,b,c;
deque < int > coada[buckets];
void solve(int &n)
{
int x,j,zz,i;
for(x = 0; x < 4; x++)
{
for( j = 1; j <= n; j++)
{
int y = (v[j] >> (8 * x)) & 255;
coada[y].push_back(v[j]);
}
for( zz = 0,i = 0; i < 256; i++)
while(!coada[i].empty())
{
v[++zz] = coada[i].front();
coada[i].pop_front();
}
}
}
int main()
{
int i;
fin >> n >> a >> b >> c;
v[1] = b;
for(i = 2; i <= n; i++)
v[i] = (1LL * a * v[i - 1] + b) % c;
solve(n);
for(i = 1; i <= n; i+= 10)
fout << v[i] <<' ';
return 0;
}