欧拉筛法

http://hi.baidu.com/nplusnplusnplu/blog/item/a8368aed9d2af221acafd5bd.html

bool IsPrime[10000001];

int Pri[2000001],PriN;

const int MaxN=1000000;

int FindPrime()

{

          memset(IsPrime,1,sizeof IsPrime);

          for(int i=2;i<=MaxN;++i)

          {

                    if(IsPrime[i])Pri[PriN++]=i;

                    for(int j=0;j<PriN;++j)

                    {

                              if(i*Pri[j]>MaxN)break;

                              IsPrime[i*Pri[j]]=0;

                              if(i%Pri[j]==0)break;

                    }

          }

}

posted on 2012-07-12 16:26  青色有角三倍速  阅读(402)  评论(0编辑  收藏  举报