TheAlgorithms-C/d4/d83/problem__401_2sol1_8c.html

466 lines
32 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<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.9.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: project_euler/problem_401/sol1.c File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">Algorithms_in_C<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.5 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('d4/d83/problem__401_2sol1_8c.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">sol1.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<p><a href="https://projecteuler.net/problem=401" target="_blank">Problem 401</a> solution - Sum of squares of divisors
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;stdint.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;time.h&gt;</code><br />
<code>#include &lt;inttypes.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for sol1.c:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/dd3/problem__401_2sol1_8c__incl.svg" width="436" height="124"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:aacbb9e1f38be71e22df1584a37c56693"><td class="memItemLeft" align="right" valign="top"><a id="aacbb9e1f38be71e22df1584a37c56693" name="aacbb9e1f38be71e22df1584a37c56693"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>__STDC_FORMAT_MACROS</b></td></tr>
<tr class="separator:aacbb9e1f38be71e22df1584a37c56693"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ade1bdf2529e3c58f53bfb4d844f3a9d3"><td class="memItemLeft" align="right" valign="top"><a id="ade1bdf2529e3c58f53bfb4d844f3a9d3" name="ade1bdf2529e3c58f53bfb4d844f3a9d3"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>MOD_LIMIT</b>&#160;&#160;&#160;(uint64_t)1e9</td></tr>
<tr class="memdesc:ade1bdf2529e3c58f53bfb4d844f3a9d3"><td class="mdescLeft">&#160;</td><td class="mdescRight">modulo limit <br /></td></tr>
<tr class="separator:ade1bdf2529e3c58f53bfb4d844f3a9d3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7a9a231e30b47bc0345749c8bd1e5077"><td class="memItemLeft" align="right" valign="top"><a id="a7a9a231e30b47bc0345749c8bd1e5077" name="a7a9a231e30b47bc0345749c8bd1e5077"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>MAX_LENGTH</b>&#160;&#160;&#160;5000</td></tr>
<tr class="memdesc:a7a9a231e30b47bc0345749c8bd1e5077"><td class="mdescLeft">&#160;</td><td class="mdescRight">chunk size of array allocation <br /></td></tr>
<tr class="separator:a7a9a231e30b47bc0345749c8bd1e5077"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a4441a6d27134cf3aed05727800d99456"><td class="memItemLeft" align="right" valign="top">char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html#a4441a6d27134cf3aed05727800d99456">is_in</a> (uint64_t N, uint64_t *D, uint64_t <a class="el" href="../../df/db3/struct_l.html">L</a>)</td></tr>
<tr class="memdesc:a4441a6d27134cf3aed05727800d99456"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if a number is present in given array. <a href="../../d4/d83/problem__401_2sol1_8c.html#a4441a6d27134cf3aed05727800d99456">More...</a><br /></td></tr>
<tr class="separator:a4441a6d27134cf3aed05727800d99456"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7380e14d595d560007b02ce516b6b215"><td class="memItemLeft" align="right" valign="top">uint64_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html#a7380e14d595d560007b02ce516b6b215">get_divisors</a> (uint64_t N, uint64_t *D)</td></tr>
<tr class="memdesc:a7380e14d595d560007b02ce516b6b215"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get all integer divisors of a number. <a href="../../d4/d83/problem__401_2sol1_8c.html#a7380e14d595d560007b02ce516b6b215">More...</a><br /></td></tr>
<tr class="separator:a7380e14d595d560007b02ce516b6b215"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a236548478af932f1115a71f601a68788"><td class="memItemLeft" align="right" valign="top">uint64_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html#a236548478af932f1115a71f601a68788">sigma2</a> (uint64_t N)</td></tr>
<tr class="memdesc:a236548478af932f1115a71f601a68788"><td class="mdescLeft">&#160;</td><td class="mdescRight">compute sum of squares of all integer factors of a number <a href="../../d4/d83/problem__401_2sol1_8c.html#a236548478af932f1115a71f601a68788">More...</a><br /></td></tr>
<tr class="separator:a236548478af932f1115a71f601a68788"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaf964739be92adc2f500e7da11e3f6be"><td class="memItemLeft" align="right" valign="top">uint64_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html#aaf964739be92adc2f500e7da11e3f6be">sigma</a> (uint64_t N)</td></tr>
<tr class="memdesc:aaf964739be92adc2f500e7da11e3f6be"><td class="mdescLeft">&#160;</td><td class="mdescRight">sum of squares of factors of numbers from 1 thru N <a href="../../d4/d83/problem__401_2sol1_8c.html#aaf964739be92adc2f500e7da11e3f6be">More...</a><br /></td></tr>
<tr class="separator:aaf964739be92adc2f500e7da11e3f6be"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3c04138a5bfe5d72780bb7e82a18e627"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a> (int argc, char **argv)</td></tr>
<tr class="memdesc:a3c04138a5bfe5d72780bb7e82a18e627"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <a href="../../d4/d83/problem__401_2sol1_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">More...</a><br /></td></tr>
<tr class="separator:a3c04138a5bfe5d72780bb7e82a18e627"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p ><a href="https://projecteuler.net/problem=401" target="_blank">Problem 401</a> solution - Sum of squares of divisors </p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kvedala" target="_blank">Krishna Vedala</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a7380e14d595d560007b02ce516b6b215" name="a7380e14d595d560007b02ce516b6b215"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7380e14d595d560007b02ce516b6b215">&#9670;&#160;</a></span>get_divisors()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint64_t get_divisors </td>
<td>(</td>
<td class="paramtype">uint64_t&#160;</td>
<td class="paramname"><em>N</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint64_t *&#160;</td>
<td class="paramname"><em>D</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Get all integer divisors of a number. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">N</td><td>number to find divisors for </td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">D</td><td>array to store divisors in </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>number of divisors found </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 48</span>{</div>
<div class="line"><span class="lineno"> 49</span> uint64_t q, r;</div>
<div class="line"><span class="lineno"> 50</span> int64_t i, num = 0;</div>
<div class="line"><span class="lineno"> 51</span> </div>
<div class="line"><span class="lineno"> 52</span> <span class="keywordflow">if</span> (N == 1)</div>
<div class="line"><span class="lineno"> 53</span> {</div>
<div class="line"><span class="lineno"> 54</span> D[0] = 1;</div>
<div class="line"><span class="lineno"> 55</span> <span class="keywordflow">return</span> 1;</div>
<div class="line"><span class="lineno"> 56</span> }</div>
<div class="line"><span class="lineno"> 57</span> </div>
<div class="line"><span class="lineno"> 58</span> <span class="comment">// search till sqrt(N)</span></div>
<div class="line"><span class="lineno"> 59</span> <span class="comment">// because after this, the pair of divisors will repeat themselves</span></div>
<div class="line"><span class="lineno"> 60</span> <span class="keywordflow">for</span> (i = 1; i * i &lt;= N + 1; i++)</div>
<div class="line"><span class="lineno"> 61</span> {</div>
<div class="line"><span class="lineno"> 62</span> r = N % i; <span class="comment">// get reminder</span></div>
<div class="line"><span class="lineno"> 63</span> </div>
<div class="line"><span class="lineno"> 64</span> <span class="comment">// reminder = 0 if &#39;i&#39; is a divisor of &#39;N&#39;</span></div>
<div class="line"><span class="lineno"> 65</span> <span class="keywordflow">if</span> (r == 0)</div>
<div class="line"><span class="lineno"> 66</span> {</div>
<div class="line"><span class="lineno"> 67</span> q = N / i;</div>
<div class="line"><span class="lineno"> 68</span> <span class="keywordflow">if</span> (!<a class="code hl_function" href="../../d4/d83/problem__401_2sol1_8c.html#a4441a6d27134cf3aed05727800d99456">is_in</a>(i, D, num)) <span class="comment">// if divisor was already stored</span></div>
<div class="line"><span class="lineno"> 69</span> {</div>
<div class="line"><span class="lineno"> 70</span> D[num] = i;</div>
<div class="line"><span class="lineno"> 71</span> num++;</div>
<div class="line"><span class="lineno"> 72</span> }</div>
<div class="line"><span class="lineno"> 73</span> <span class="keywordflow">if</span> (!<a class="code hl_function" href="../../d4/d83/problem__401_2sol1_8c.html#a4441a6d27134cf3aed05727800d99456">is_in</a>(q, D, num)) <span class="comment">// if divisor was already stored</span></div>
<div class="line"><span class="lineno"> 74</span> {</div>
<div class="line"><span class="lineno"> 75</span> D[num] = q;</div>
<div class="line"><span class="lineno"> 76</span> num++;</div>
<div class="line"><span class="lineno"> 77</span> }</div>
<div class="line"><span class="lineno"> 78</span> }</div>
<div class="line"><span class="lineno"> 79</span> </div>
<div class="line"><span class="lineno"> 80</span> <span class="keywordflow">if</span> (num == <a class="code hl_define" href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a>)</div>
<div class="line"><span class="lineno"> 81</span> { <span class="comment">// limit of array reached, allocate more space</span></div>
<div class="line"><span class="lineno"> 82</span> D = (uint64_t *)realloc(D, <a class="code hl_define" href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a> * <span class="keyword">sizeof</span>(uint64_t) &lt;&lt; 1);</div>
<div class="line"><span class="lineno"> 83</span> }</div>
<div class="line"><span class="lineno"> 84</span> }</div>
<div class="line"><span class="lineno"> 85</span> <span class="keywordflow">return</span> num;</div>
<div class="line"><span class="lineno"> 86</span>}</div>
<div class="ttc" id="aproblem__401_2sol1_8c_html_a4441a6d27134cf3aed05727800d99456"><div class="ttname"><a href="../../d4/d83/problem__401_2sol1_8c.html#a4441a6d27134cf3aed05727800d99456">is_in</a></div><div class="ttdeci">char is_in(uint64_t N, uint64_t *D, uint64_t L)</div><div class="ttdoc">Check if a number is present in given array.</div><div class="ttdef"><b>Definition:</b> sol1.c:28</div></div>
<div class="ttc" id="aproblem__401_2sol1_8c_html_a7a9a231e30b47bc0345749c8bd1e5077"><div class="ttname"><a href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a></div><div class="ttdeci">#define MAX_LENGTH</div><div class="ttdoc">chunk size of array allocation</div><div class="ttdef"><b>Definition:</b> sol1.c:18</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d83/problem__401_2sol1_8c_a7380e14d595d560007b02ce516b6b215_cgraph.svg" width="200" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="a4441a6d27134cf3aed05727800d99456" name="a4441a6d27134cf3aed05727800d99456"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4441a6d27134cf3aed05727800d99456">&#9670;&#160;</a></span>is_in()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">char is_in </td>
<td>(</td>
<td class="paramtype">uint64_t&#160;</td>
<td class="paramname"><em>N</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint64_t *&#160;</td>
<td class="paramname"><em>D</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint64_t&#160;</td>
<td class="paramname"><em>L</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Check if a number is present in given array. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">N</td><td>number to check </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">D</td><td>array to check </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname"><a class="el" href="../../df/db3/struct_l.html">L</a></td><td>length of array </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>1 if present </dd>
<dd>
0 if absent </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 29</span>{</div>
<div class="line"><span class="lineno"> 30</span> uint64_t i;</div>
<div class="line"><span class="lineno"> 31</span> <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>; i++)</div>
<div class="line"><span class="lineno"> 32</span> {</div>
<div class="line"><span class="lineno"> 33</span> <span class="keywordflow">if</span> (D[i] == N)</div>
<div class="line"><span class="lineno"> 34</span> {</div>
<div class="line"><span class="lineno"> 35</span> <span class="keywordflow">return</span> 1;</div>
<div class="line"><span class="lineno"> 36</span> }</div>
<div class="line"><span class="lineno"> 37</span> }</div>
<div class="line"><span class="lineno"> 38</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 39</span>}</div>
<div class="ttc" id="astruct_l_html"><div class="ttname"><a href="../../df/db3/struct_l.html">L</a></div><div class="ttdef"><b>Definition:</b> list.h:8</div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a3c04138a5bfe5d72780bb7e82a18e627" name="a3c04138a5bfe5d72780bb7e82a18e627"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3c04138a5bfe5d72780bb7e82a18e627">&#9670;&#160;</a></span>main()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int main </td>
<td>(</td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>argc</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">char **&#160;</td>
<td class="paramname"><em>argv</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Main function. </p>
<div class="fragment"><div class="line"><span class="lineno"> 133</span>{</div>
<div class="line"><span class="lineno"> 134</span> uint64_t N = 1000;</div>
<div class="line"><span class="lineno"> 135</span> </div>
<div class="line"><span class="lineno"> 136</span> <span class="keywordflow">if</span> (argc == 2)</div>
<div class="line"><span class="lineno"> 137</span> {</div>
<div class="line"><span class="lineno"> 138</span> N = strtoll(argv[1], NULL, 10);</div>
<div class="line"><span class="lineno"> 139</span> }</div>
<div class="line"><span class="lineno"> 140</span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argc &gt; 2)</div>
<div class="line"><span class="lineno"> 141</span> {</div>
<div class="line"><span class="lineno"> 142</span> fprintf(stderr, <span class="stringliteral">&quot;Wrong number of input arguments!\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 143</span> printf(<span class="stringliteral">&quot;Usage:\t ./sol1.c [N=1000]&quot;</span>);</div>
<div class="line"><span class="lineno"> 144</span> <span class="keywordflow">return</span> -1;</div>
<div class="line"><span class="lineno"> 145</span> }</div>
<div class="line"><span class="lineno"> 146</span> </div>
<div class="line"><span class="lineno"> 147</span> clock_t start_time = clock();</div>
<div class="line"><span class="lineno"> 148</span> uint64_t result = <a class="code hl_function" href="../../d4/d83/problem__401_2sol1_8c.html#aaf964739be92adc2f500e7da11e3f6be">sigma</a>(N);</div>
<div class="line"><span class="lineno"> 149</span> <span class="keywordtype">double</span> dtime = clock() - start_time;</div>
<div class="line"><span class="lineno"> 150</span> </div>
<div class="line"><span class="lineno"> 151</span> printf(<span class="stringliteral">&quot;N = %&quot;</span> PRIu64 <span class="stringliteral">&quot;\nSum: %&quot;</span> PRIu64 <span class="stringliteral">&quot;\n&quot;</span>, N, result);</div>
<div class="line"><span class="lineno"> 152</span> printf(<span class="stringliteral">&quot;Time taken: %.4gms\n&quot;</span>, dtime * 1e3 / CLOCKS_PER_SEC);</div>
<div class="line"><span class="lineno"> 153</span> </div>
<div class="line"><span class="lineno"> 154</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 155</span>}</div>
<div class="ttc" id="aproblem__401_2sol1_8c_html_aaf964739be92adc2f500e7da11e3f6be"><div class="ttname"><a href="../../d4/d83/problem__401_2sol1_8c.html#aaf964739be92adc2f500e7da11e3f6be">sigma</a></div><div class="ttdeci">uint64_t sigma(uint64_t N)</div><div class="ttdoc">sum of squares of factors of numbers from 1 thru N</div><div class="ttdef"><b>Definition:</b> sol1.c:114</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d83/problem__401_2sol1_8c_a3c04138a5bfe5d72780bb7e82a18e627_cgraph.svg" width="516" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="aaf964739be92adc2f500e7da11e3f6be" name="aaf964739be92adc2f500e7da11e3f6be"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aaf964739be92adc2f500e7da11e3f6be">&#9670;&#160;</a></span>sigma()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint64_t sigma </td>
<td>(</td>
<td class="paramtype">uint64_t&#160;</td>
<td class="paramname"><em>N</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>sum of squares of factors of numbers from 1 thru N </p>
<div class="fragment"><div class="line"><span class="lineno"> 115</span>{</div>
<div class="line"><span class="lineno"> 116</span> uint64_t s, sum = 0;</div>
<div class="line"><span class="lineno"> 117</span> int64_t i;</div>
<div class="line"><span class="lineno"> 118</span> </div>
<div class="line"><span class="lineno"> 119</span><span class="preprocessor">#ifdef _OPENMP</span></div>
<div class="line"><span class="lineno"> 120</span><span class="comment">// parallelize on threads</span></div>
<div class="line"><span class="lineno"> 121</span><span class="preprocessor">#pragma omp parallel for reduction(+ : sum)</span></div>
<div class="line"><span class="lineno"> 122</span><span class="preprocessor">#endif</span></div>
<div class="line"><span class="lineno"> 123</span> <span class="keywordflow">for</span> (i = 0; i &lt;= N; i++)</div>
<div class="line"><span class="lineno"> 124</span> {</div>
<div class="line"><span class="lineno"> 125</span> s = <a class="code hl_function" href="../../d4/d83/problem__401_2sol1_8c.html#a236548478af932f1115a71f601a68788">sigma2</a>(i);</div>
<div class="line"><span class="lineno"> 126</span> sum += s;</div>
<div class="line"><span class="lineno"> 127</span> }</div>
<div class="line"><span class="lineno"> 128</span> <span class="keywordflow">return</span> sum % <a class="code hl_define" href="../../d4/d83/problem__401_2sol1_8c.html#ade1bdf2529e3c58f53bfb4d844f3a9d3">MOD_LIMIT</a>;</div>
<div class="line"><span class="lineno"> 129</span>}</div>
<div class="ttc" id="aproblem__401_2sol1_8c_html_a236548478af932f1115a71f601a68788"><div class="ttname"><a href="../../d4/d83/problem__401_2sol1_8c.html#a236548478af932f1115a71f601a68788">sigma2</a></div><div class="ttdeci">uint64_t sigma2(uint64_t N)</div><div class="ttdoc">compute sum of squares of all integer factors of a number</div><div class="ttdef"><b>Definition:</b> sol1.c:93</div></div>
<div class="ttc" id="aproblem__401_2sol1_8c_html_ade1bdf2529e3c58f53bfb4d844f3a9d3"><div class="ttname"><a href="../../d4/d83/problem__401_2sol1_8c.html#ade1bdf2529e3c58f53bfb4d844f3a9d3">MOD_LIMIT</a></div><div class="ttdeci">#define MOD_LIMIT</div><div class="ttdoc">modulo limit</div><div class="ttdef"><b>Definition:</b> sol1.c:17</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d83/problem__401_2sol1_8c_aaf964739be92adc2f500e7da11e3f6be_cgraph.svg" width="418" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="a236548478af932f1115a71f601a68788" name="a236548478af932f1115a71f601a68788"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a236548478af932f1115a71f601a68788">&#9670;&#160;</a></span>sigma2()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">uint64_t sigma2 </td>
<td>(</td>
<td class="paramtype">uint64_t&#160;</td>
<td class="paramname"><em>N</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>compute sum of squares of all integer factors of a number </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">N</td><td></td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>sum of squares </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 94</span>{</div>
<div class="line"><span class="lineno"> 95</span> uint64_t sum = 0, <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>;</div>
<div class="line"><span class="lineno"> 96</span> int64_t i;</div>
<div class="line"><span class="lineno"> 97</span> uint64_t *D = (uint64_t *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<a class="code hl_define" href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a> * <span class="keyword">sizeof</span>(uint64_t));</div>
<div class="line"><span class="lineno"> 98</span> </div>
<div class="line"><span class="lineno"> 99</span> <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a> = <a class="code hl_function" href="../../d4/d83/problem__401_2sol1_8c.html#a7380e14d595d560007b02ce516b6b215">get_divisors</a>(N, D);</div>
<div class="line"><span class="lineno"> 100</span> <span class="keywordflow">for</span> (i = 1; i &lt; <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>; i++)</div>
<div class="line"><span class="lineno"> 101</span> {</div>
<div class="line"><span class="lineno"> 102</span> uint64_t DD = (D[i] * D[i]) % <a class="code hl_define" href="../../d4/d83/problem__401_2sol1_8c.html#ade1bdf2529e3c58f53bfb4d844f3a9d3">MOD_LIMIT</a>;</div>
<div class="line"><span class="lineno"> 103</span> sum += DD;</div>
<div class="line"><span class="lineno"> 104</span> }</div>
<div class="line"><span class="lineno"> 105</span> </div>
<div class="line"><span class="lineno"> 106</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(D);</div>
<div class="line"><span class="lineno"> 107</span> <span class="keywordflow">return</span> sum % <a class="code hl_define" href="../../d4/d83/problem__401_2sol1_8c.html#ade1bdf2529e3c58f53bfb4d844f3a9d3">MOD_LIMIT</a>;</div>
<div class="line"><span class="lineno"> 108</span>}</div>
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:18</div></div>
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:26</div></div>
<div class="ttc" id="aproblem__401_2sol1_8c_html_a7380e14d595d560007b02ce516b6b215"><div class="ttname"><a href="../../d4/d83/problem__401_2sol1_8c.html#a7380e14d595d560007b02ce516b6b215">get_divisors</a></div><div class="ttdeci">uint64_t get_divisors(uint64_t N, uint64_t *D)</div><div class="ttdoc">Get all integer divisors of a number.</div><div class="ttdef"><b>Definition:</b> sol1.c:47</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d83/problem__401_2sol1_8c_a236548478af932f1115a71f601a68788_cgraph.svg" width="312" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_b3d331eabd4234f247030c297aaf021c.html">project_euler</a></li><li class="navelem"><a class="el" href="../../dir_2f070f19f76dfadabbc24fe483d7e98d.html">problem_401</a></li><li class="navelem"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html">sol1.c</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.9.5 </li>
</ul>
</div>
</body>
</html>