在线性时间里求素数表 12345678910111213141516171819202122232425262728#include<cstdio>#include<cstring>const int maxn = 1000000;bool isPrime[maxn];int table[maxn];int cnt;void getPrime(){ memset(isPrime,1,sizeof(isPrime)); cnt = 0; isPrime[1] = 0; for(int i = 2; i < maxn; i++){ if(isPrime[i]){ table[++cnt] = i; } for(int j = 1; j <= cnt && i * table[j] < maxn; j ++){ isPrime[i*table[j]] = 0; } }}int main(){ getPrime(); for(int i = 1; i <= 20; i ++) { printf("%d\n",table[i]); }}