#include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[]) { int i = 2, j = 0; long N = atol(argv[1]); int *a = malloc(N*sizeof(int)); if (NULL == a) { printf("There is no enough memory! "); return -1; } for(i=2; i<N; i++) a[i] = 1; for(i=2; i<N; i++) { if(a[i]) { for(j=i; j*i<N; j++) { a[i*j] = 0; } } } for(i=2; i<N; i++) { if(a[i]) printf("%4d ", i); } printf(" "); return 0; }