版本比较
埃氏筛法总结
正文
增加 3 行删除 3 行
2 行未改动34567789101116 行未改动2829303132323334353616 行未改动5354555657575859606111 行未改动2 行未改动
本文章已被收录于[这篇整合文章](https://www.luogu.com.cn/blog/WangYiming2023/The-Mathematics-of-OI),并有更多相关拓展内容。
#### _拿质数筛举例:_ #### _拿质数筛举例:_ ```cpp//cpp·求100以内质数int a[100]={1,2,3,4,...,97,98,99,100};```16 行未改动在尝试几次,得到了所有质因数(↑如上所示,其实没变)。
由此,就成功地筛出了100以内的素数(质数)。
_Code:_ _Code:_
```cpp#include<bits/stdc++.h>using namespace std;16 行未改动 cout<<i<<endl; } } return 0;} }```
## 附P.S.:1. 埃氏(eratosthenes)筛实质上是通过打标记的方式,利用已有质数的倍数来筛选更大的合数并去掉它们,**时间复杂度为( _N_ log log _N_ )**,(ヾ(゚∀゚ゞ)太香了!)。11 行未改动