回复 9楼 Devil_W
程序代码:
#include <stdio.h> #define N 1000000 char a[N]; int main(void) { int prime[100000] = {0}; int i,j, nPrime; nPrime = 0; for (i = 2; i < N; i++) a[i]= '1'; for (i = 2; i < N; i++) { if (a[i]) prime[nPrime++] = i; for (j = 0; j < nPrime && i*(prime[j]) < N; j++) a[i*prime[j]] = '\0'; } for (i = 2; i < N; i++) { if (a[i]) printf("%d ", i); } printf("\n"); return 0; }
我就是真命天子,顺我者生,逆我者死!