mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-05-02 14:31:57 +08:00
Documentation for c26eea874d
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.12.0"/>
|
||||
<meta name="generator" content="Doxygen 1.13.2"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>TheAlgorithms/C++: math/sieve_of_eratosthenes.cpp Source File</title>
|
||||
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
||||
@@ -60,7 +60,7 @@ window.MathJax = {
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.12.0 -->
|
||||
<!-- Generated by Doxygen 1.13.2 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
||||
@@ -124,16 +124,17 @@ $(function(){initNavTree('d8/ddf/sieve__of__eratosthenes_8cpp_source.html','../.
|
||||
<div class="headertitle"><div class="title">sieve_of_eratosthenes.cpp</div></div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<a href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
|
||||
<a href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span></div>
|
||||
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span> </div>
|
||||
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="preprocessor">#include <cstdint></span></div>
|
||||
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="preprocessor">#include <cassert></span> </div>
|
||||
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="preprocessor">#include <iostream></span> </div>
|
||||
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span><span class="preprocessor">#include <vector></span> </div>
|
||||
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span> </div>
|
||||
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span></div>
|
||||
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../dd/d47/namespacemath.html">math</a> {</div>
|
||||
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../d2/db0/namespacesieve__of__eratosthenes.html">sieve_of_eratosthenes</a> {</div>
|
||||
<div class="foldopen" id="foldopen00045" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"><a class="line" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a22be949d160b26361f7e323310f7fa0c"> 45</a></span>std::vector<bool> <a class="code hl_function" href="../../dd/d47/namespacemath.html#a91366864111e1fac29722ca45e02ea8f">sieve</a>(uint32_t N) {</div>
|
||||
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"><a class="line" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a22be949d160b26361f7e323310f7fa0c"> 45</a></span>std::vector<bool> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a22be949d160b26361f7e323310f7fa0c">sieve</a>(uint32_t N) {</div>
|
||||
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> std::vector<bool> <a class="code hl_function" href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">is_prime</a>(N + 1, <span class="keyword">true</span>); <span class="comment">// Initialize all as prime numbers</span></div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> <a class="code hl_function" href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">is_prime</a>[0] = <a class="code hl_function" href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">is_prime</a>[1] = <span class="keyword">false</span>; <span class="comment">// 0 and 1 are not prime numbers</span></div>
|
||||
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> </div>
|
||||
@@ -147,9 +148,9 @@ $(function(){initNavTree('d8/ddf/sieve__of__eratosthenes_8cpp_source.html','../.
|
||||
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> <span class="keywordflow">return</span> <a class="code hl_function" href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">is_prime</a>;</div>
|
||||
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span>}</div>
|
||||
</div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> </div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span></div>
|
||||
<div class="foldopen" id="foldopen00065" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"><a class="line" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a55bc4a221e584d33b79b322432ecc0f3"> 65</a></span><span class="keywordtype">void</span> print(uint32_t N, <span class="keyword">const</span> std::vector<bool> &<a class="code hl_function" href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">is_prime</a>) {</div>
|
||||
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"><a class="line" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a55bc4a221e584d33b79b322432ecc0f3"> 65</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a55bc4a221e584d33b79b322432ecc0f3">print</a>(uint32_t N, <span class="keyword">const</span> std::vector<bool> &<a class="code hl_function" href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">is_prime</a>) {</div>
|
||||
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <span class="keywordflow">for</span> (uint32_t i = 2; i <= N; i++) {</div>
|
||||
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">is_prime</a>[i]) {</div>
|
||||
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> std::cout << i << <span class="charliteral">' '</span>;</div>
|
||||
@@ -161,15 +162,15 @@ $(function(){initNavTree('d8/ddf/sieve__of__eratosthenes_8cpp_source.html','../.
|
||||
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> </div>
|
||||
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span>} <span class="comment">// namespace sieve_of_eratosthenes</span></div>
|
||||
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span>} <span class="comment">// namespace math</span></div>
|
||||
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> </div>
|
||||
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span></div>
|
||||
<div class="foldopen" id="foldopen00081" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"><a class="line" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e"> 81</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>() {</div>
|
||||
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> std::vector<bool> is_prime_1 =</div>
|
||||
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> math::sieve_of_eratosthenes::sieve(<span class="keyword">static_cast<</span>uint32_t<span class="keyword">></span>(10));</div>
|
||||
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a22be949d160b26361f7e323310f7fa0c">math::sieve_of_eratosthenes::sieve</a>(<span class="keyword">static_cast<</span>uint32_t<span class="keyword">></span>(10));</div>
|
||||
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> std::vector<bool> is_prime_2 =</div>
|
||||
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> math::sieve_of_eratosthenes::sieve(<span class="keyword">static_cast<</span>uint32_t<span class="keyword">></span>(20));</div>
|
||||
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a22be949d160b26361f7e323310f7fa0c">math::sieve_of_eratosthenes::sieve</a>(<span class="keyword">static_cast<</span>uint32_t<span class="keyword">></span>(20));</div>
|
||||
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> std::vector<bool> is_prime_3 =</div>
|
||||
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> math::sieve_of_eratosthenes::sieve(<span class="keyword">static_cast<</span>uint32_t<span class="keyword">></span>(100));</div>
|
||||
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a22be949d160b26361f7e323310f7fa0c">math::sieve_of_eratosthenes::sieve</a>(<span class="keyword">static_cast<</span>uint32_t<span class="keyword">></span>(100));</div>
|
||||
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> </div>
|
||||
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> std::vector<bool> expected_1{<span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">true</span>, <span class="keyword">true</span>, <span class="keyword">false</span>, <span class="keyword">true</span>,</div>
|
||||
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> <span class="keyword">false</span>, <span class="keyword">true</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>};</div>
|
||||
@@ -197,7 +198,7 @@ $(function(){initNavTree('d8/ddf/sieve__of__eratosthenes_8cpp_source.html','../.
|
||||
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> </div>
|
||||
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span>}</div>
|
||||
</div>
|
||||
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> </div>
|
||||
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span></div>
|
||||
<div class="foldopen" id="foldopen00119" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"><a class="line" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4"> 119</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() {</div>
|
||||
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> <a class="code hl_function" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>();</div>
|
||||
@@ -205,10 +206,11 @@ $(function(){initNavTree('d8/ddf/sieve__of__eratosthenes_8cpp_source.html','../.
|
||||
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span>}</div>
|
||||
</div>
|
||||
<div class="ttc" id="anamespacemath_html"><div class="ttname"><a href="../../dd/d47/namespacemath.html">math</a></div><div class="ttdoc">for assert</div></div>
|
||||
<div class="ttc" id="anamespacemath_html_a91366864111e1fac29722ca45e02ea8f"><div class="ttname"><a href="../../dd/d47/namespacemath.html#a91366864111e1fac29722ca45e02ea8f">math::sieve</a></div><div class="ttdeci">void sieve(std::vector< bool > *vec)</div><div class="ttdoc">Performs the sieve.</div><div class="ttdef"><b>Definition</b> <a href="../../d7/da6/eratosthenes_8cpp_source.html#l00033">eratosthenes.cpp:33</a></div></div>
|
||||
<div class="ttc" id="anamespacemath_html_abd8f794b2229b42876169ff841b6e444"><div class="ttname"><a href="../../dd/d47/namespacemath.html#abd8f794b2229b42876169ff841b6e444">math::is_prime</a></div><div class="ttdeci">bool is_prime(int64_t num)</div><div class="ttdoc">Function to check if the given number is prime or not.</div><div class="ttdef"><b>Definition</b> <a href="../../db/d93/check__prime_8cpp_source.html#l00031">check_prime.cpp:31</a></div></div>
|
||||
<div class="ttc" id="anamespacesieve__of__eratosthenes_html"><div class="ttname"><a href="../../d2/db0/namespacesieve__of__eratosthenes.html">sieve_of_eratosthenes</a></div><div class="ttdoc">Functions for finding Prime Numbers using Sieve of Eratosthenes.</div></div>
|
||||
<div class="ttc" id="asieve__of__eratosthenes_8cpp_html_a22be949d160b26361f7e323310f7fa0c"><div class="ttname"><a href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a22be949d160b26361f7e323310f7fa0c">math::sieve_of_eratosthenes::sieve</a></div><div class="ttdeci">std::vector< bool > sieve(uint32_t N)</div><div class="ttdoc">Function to sieve out the primes.</div><div class="ttdef"><b>Definition</b> <a href="#l00045">sieve_of_eratosthenes.cpp:45</a></div></div>
|
||||
<div class="ttc" id="asieve__of__eratosthenes_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> <a href="#l00081">sieve_of_eratosthenes.cpp:81</a></div></div>
|
||||
<div class="ttc" id="asieve__of__eratosthenes_8cpp_html_a55bc4a221e584d33b79b322432ecc0f3"><div class="ttname"><a href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#a55bc4a221e584d33b79b322432ecc0f3">math::sieve_of_eratosthenes::print</a></div><div class="ttdeci">void print(uint32_t N, const std::vector< bool > &is_prime)</div><div class="ttdoc">Function to print the prime numbers.</div><div class="ttdef"><b>Definition</b> <a href="#l00065">sieve_of_eratosthenes.cpp:65</a></div></div>
|
||||
<div class="ttc" id="asieve__of__eratosthenes_8cpp_html_ae66f6b31b5ad750f1fe042a706a4e3d4"><div class="ttname"><a href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a></div><div class="ttdeci">int main()</div><div class="ttdoc">Main function.</div><div class="ttdef"><b>Definition</b> <a href="#l00119">sieve_of_eratosthenes.cpp:119</a></div></div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
</div><!-- doc-content -->
|
||||
@@ -216,7 +218,7 @@ $(function(){initNavTree('d8/ddf/sieve__of__eratosthenes_8cpp_source.html','../.
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="../../dir_296d53ceaeaa7e099814a6def439fe8a.html">math</a></li><li class="navelem"><a class="el" href="../../d8/ddf/sieve__of__eratosthenes_8cpp.html">sieve_of_eratosthenes.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0 </li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.2 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user