#include<stdio.h>
#include<math.h>
char pmap[5001];
int primes[1000];
int find(int n)
{
int i,t,e=(int)(sqrt((double)n)+0.0001);
for (i=3; i<=e; i+=2)
for (t=pmap[i>>1]*n+i*i; t<=n; t+=i+i)
pmap[t>>1]=1;
for (primes[t=0]=2,i=3,e=n/2-1; i<=e; ++i)
if (!pmap[i]) primes[++t]=(i<<1)+1;
return t+1;
}
int main()
{
int n = find(1000);
for (int i=0; i<n; ++i)
{
printf("%d,", primes[i]);
}
printf("\n共%d个素数\n", n);
return 0;
}
[
本帖最后由 Aion 于 2009-10-11 12:52 编辑 ]