素数筛法

来源:互联网 发布:中企动力源码 编辑:程序博客网 时间:2024/06/03 21:11
  1. #include<cstdio>  
  2. #include<algorithm>  
  3. #include<cmath>  
  4. #include<cstring>  
  5. #include<iostream>  
  6. using namespace std;  
  7. const int L=1000005,inf=1<<30,maxn=1005;  
  8. int prime[L];  
  9. bool is[L];  
  10. void getPrime()  
  11. {  
  12.     fill(is,is+L,1);  
  13.     is[1]=0;  
  14.     int np=0;  
  15.     for(int i=2;i<L;i++)  
  16.         if(is[i])  
  17.         {  
  18.             prime[++np]=i;  
  19.             for(int j=2*i;j<L;j+=i) is[j]=0;  
  20.         }  
  21.    // for(int i=1;i<=np;i++)  
  22.         //cout<<prime[i]<<" ";  
  23. }  
  24. int main()  
  25. {  
  26.     getPrime();  
  27.     return 0;  
  28. }  
  29. 转载自:http://blog.csdn.net/u013615904/article/details/41786507
原创粉丝点击