线性筛

好像有叫做线性素数筛的东西,而且我不知道我的是不是;

至于为怎么写这篇文章,其实就是背不过,然后以后复习用;

鉴于以上目的,我就直接上代码了,挺好背的,背过就好了;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#include<cstdio>
#include<algorithm>
#define II int
#define R register
#define I 2000000
using namespace std;

II n,_tot;
II op[I], is[I];

void ()
{
for(R II i=2;i<=I-100;i++)
{
if(!is[i]) op[++_tot]=i;
for(R II j=1;j<=_tot && op[j]*i<=I-100;j++) {
is[op[j]*i]=1;
if(i%op[j]==0) break ;
}
}
}


int main()
{
scanf("%d",&n); sss();
for(R II i=1;i<=_tot;i++)
if(op[i]>=n&&(!is[i])) {
printf("%dn",op[i]);
exit(0);
}
}

by pretend-fal

END;