Problem:
List of primes between [L, R]
Solution:
First, the Prime table on [1...sqrt (R)] was obtained by using the wagered sieve method.
And then, on [L, R], we use wagered sieve method to calculate prime number.
Const intN (1e5);BOOLIsprime[n];intPrime[n];voidinit () {memset (IsPrime,-1,sizeof(IsPrime)); isprime[0]=isprime[1]=0; intnp=0; for(intI=0; i<n; i++){ if(Isprime[i]) {PRIME[NP++]=i; for(intj=2*i; j<n; j+=i) isprime[j]=0; }}}typedefLong Longll;Const intM (1e5);BOOLOk[m];intRes[m];intSeive (ll L, ll R) {//L, R >=1memset (OK,-1,sizeof(OK)); if(l==1) ok[0]=0;//Error-prone intk=sqrt (R); for(intI=0; prime[i]<=k; i++) {ll J= (l+prime[i]-1)/prime*Prime; J=max (J, (LL)2*Prime[i]); for(; j<=r; j+=Prime[i]) ok[j-l]=0; } intnp=0; for(intI=0; i<=r-l; i++) if(Ok[i]) res[np++]=i+(LL) L; returnNP;}
General wording of the Ed sieve method