#include <stdio.h>
#include <stdlib.h>
int main() {
int i, n, j;
int *x;
printf("N = ? ");
scanf("%d", &n);
if ((x = malloc(sizeof(int) * n)) == NULL) {
fprintf(stderr, "no memory.\n");
exit(-1);
}
for (i = 0; i < n; i++)
x[i] = 0;
x[0] = x[1] = 1;
for (i = 2; i < n; i++) {
if (x[i] == 0) {
printf("%d, ", i);
for (j = i + i; j < n; j += i)
x[j] = 1;
}
}
free(x);
return 0;
}
/* end */