for(size_t j=0;j<coprime;j++){advance();}state-=coprime;}while(l<r){advance();}}constexpr dynamic_bit_array sieve210(uint32_t N){N++;dynamic_bit_array prime(to_ord(N));prime.set_all();static const auto[wheels,medium_primes_begin]=[](){constexpr size_t max_wheel_size=1<<21;uint32_t product=period*dynamic_bit_array::width;big_vector<uint32_t>current;big_vector<wheel_t>wheels;for(size_t i=0;i<size(sqrt_primes);i++){uint32_t p=sqrt_primes[i];if(product*p>max_wheel_size){wheels.push_back(make_wheel(current,product));current={p};product=period*dynamic_bit_array::width*p;if(product>max_wheel_size){checkpoint("make wheels");return std::pair{wheels,i};}}else{current.push_back(p);product*=p;}}assert(false);}();static constexpr uint32_t dense_block=1<<25;for(uint32_t start=0;start<N;start+=dense_block){uint32_t r=std::min(start+dense_block,N);for(auto const&wheel:wheels){auto l=start/wheel.product*wheel.product;sieve_dense(prime,to_ord(l),to_ord(r),wheel);}}checkpoint("dense sieve");static constexpr uint32_t sparse_block=1<<24;for(uint32_t start=0;start<N;start+=sparse_block){uint32_t r=std::min(start+sparse_block,N);for(size_t i=medium_primes_begin;i<size(sqrt_primes);i++){auto p=sqrt_primes[i];if(p*p>=r)break;auto k=std::max(start/p,p);if(!coprime210(k)){k+=add210[k%210];}sieve210(prime,to_ord(p*k),to_ord(r),i,state210[k%210]);}}checkpoint("sparse sieve");for(size_t i=0;i<std::min(prime.words,sqrt_prime_bits.words);i++){prime.word(i)=sqrt_prime_bits.word(i);}return prime;}}
0 commit comments