#include <iostream>
using namespace std;
int main()
{
int prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,
47,53,59,61,67,71,73,79,83,89,97}; //100以内的质数
int seq[10000];
for(int i=0; i<10000; ++i)
seq[i]=1;
for(int i=0; i<25; ++i)
{
for(int j=1; j*prime[i]<10000; ++j)
{
int temp=j*prime[i];
seq[temp]=0;
}
}
for(int i=101; i<10000; ++i)
if(seq[i]==1)
cout<<i<<'\t';
}
另:补充一个短小精悍的求质数的程序
#include <cstdio>
using namespace std;
int prime[20000];
void main() {
int tmp,i=2;
while ((tmp=i)<20000)
if ((!prime[i++]) && (printf("%8d",i-1)))
while ((tmp+i-1)<20000) prime[tmp+=i-1]=1; //将i-1的倍数全部置为1
}