线性筛素数

#include
#define re return
#define inc(i,l,r) for(register int i=l;i<=r;++i)

using namespace std;
char buf[1<<21],*p1,*p2;
inline int gc(){re p1==p2 and(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}

templateinline void rd(T&x)
{
	char c;bool f=0;
	while((c=gc())<'0'||c>'9')if(c=='-')f=1;
	x=c^48;
	while((c=gc())>='0' and c<='9')x=x*10+(c^48);
	if(f)x=-x;
}

int l,r,n,m,cnt,sum[1000005],prime[100005];
bool noprime[1000005];
int main()
{
	freopen("in.txt","r",stdin);
	
	rd(n),rd(m);
	noprime[1]=1;
	inc(i,2,m)
	{
		sum[i]=sum[i-1];
		if(!noprime[i]){prime[++cnt]=i;++sum[i];}
		for(int j=1;j<=cnt,i*prime[j]<=m;++j)
		{
			noprime[prime[j]*i]=1;
			if(i%prime[j]==0)break;
		}
	}

	re 0;
}

2. Miller_Rabin算法
3. 大于等于5的质数一定和6的倍数相邻

你可能感兴趣的:(数论)