Fork me on GitHub

线性筛素数

https://www.luogu.org/problem/show?pid=3383#sub

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#define L long
#define M 200000007
using namespace std;
L prime[M],cnt=0;
bool notprime[M];
int main()
{
    freopen("a.out","w",stdout);
    notprime[0]=1,notprime[1]=1;
    for(L i=2;i<M;i++)
    {
        if(!notprime[i])
         prime[++cnt]=i;

        for(L j=1;j<=cnt&&i*prime[j]<M;j++)
        {
            notprime[i*prime[j]]=1;
            if(i%prime[j]==0) break;
        }           
    }//线性筛素数 
    return 0;
} 
posted @ 2017-09-24 17:48  primes  阅读(108)  评论(0编辑  收藏  举报