- ////**筛选法求素数*/////
- #include <stdio.h>
- #define N 1000010
- int a[N]={0};
- int main()
- {
- int i,j,k=0,d,s;
- a[0]=a[1]=1;
- for(i=2;i<N;i++)
- if(a[i]!=1)
- for(j=i+i;j<N;j+=i)
- a[j]=1;
- for(i=2;i<N;i++)
- if(!a[i]) printf("%d ",i);
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/201120137322.html
来源: http://www.codesnippet.cn/detail/201120137322.html