1.特点
在[1,n]区间中,筛出所有质数,并存入prm数组中.时间复杂度O(n) .
2.代码实现
vector prm;
bitset <le7(数据范围)> np ;
void (const int N=le7){
....for (int i=1;i< = N ;i++){
.......,if(!np[2]) {
,,...,.,,.prm. push-back (i) ; ,,,....}
.,.,,.,for(anto j : prm){
...… .......if(i*j>N) break;
.,,.,,..,,.else{
.,.....:..,,..int k = i * j ;
…..… ..........np[ k]= 1 ;
.....,....,,.,if (i%j = =0) break;
,..........}
..,.,,. }
}