Pagini recente » Cod sursa (job #2500298) | Cod sursa (job #380798) | Cod sursa (job #2183588) | Cod sursa (job #2535709) | Cod sursa (job #1128419)
#include <cstdio>
#include <deque>
#define LL long long
#define NMAX 10000007
using namespace std;
deque< int > v[10];
int a[NMAX];
int n, A, B, C;
int main(){
freopen("radixsort.in", "r", stdin);
freopen("radixsort.out", "w", stdout);
scanf("%d %d %d %d", &n, &A, &B, &C);
a[1] = B;
for(int i = 2; i <= n; ++i)
a[i] = ((LL)A * a[i - 1] + B) % C;
int Put = 1;
while(Put < 1000000001){
for(int i = 0; i <= 9; ++i)
v[i].clear();
for(int i = 1; i <= n; ++i)
v[(a[i] / Put) % 10].push_back(a[i]);
n = 0;
for(int i = 0; i <= 9; ++i)
for(int j = 0; j < v[i].size(); ++j)
a[++ n] = v[i][j];
Put *= 10;
}
for(int i = 1; i <= n; i += 10)
printf("%d ", a[i]);
return 0;
}