mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
358 lines
25 KiB
HTML
358 lines
25 KiB
HTML
<!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">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.20"/>
|
|
<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 style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">Algorithms_in_C
|
|
 <span id="projectnumber">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.8.20 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
|
|
/* @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:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(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:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(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">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#define-members">Macros</a> |
|
|
<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">Problem 401</a> solution - Sum of squares of divisors
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <stdint.h></code><br />
|
|
<code>#include <stdio.h></code><br />
|
|
<code>#include <stdlib.h></code><br />
|
|
<code>#include <time.h></code><br />
|
|
<code>#include <inttypes.h></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="127"><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 name="define-members"></a>
|
|
Macros</h2></td></tr>
|
|
<tr class="memitem:aacbb9e1f38be71e22df1584a37c56693"><td class="memItemLeft" align="right" valign="top"><a id="aacbb9e1f38be71e22df1584a37c56693"></a>
|
|
#define </td><td class="memItemRight" valign="bottom"><b>__STDC_FORMAT_MACROS</b></td></tr>
|
|
<tr class="separator:aacbb9e1f38be71e22df1584a37c56693"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ade1bdf2529e3c58f53bfb4d844f3a9d3"><td class="memItemLeft" align="right" valign="top"><a id="ade1bdf2529e3c58f53bfb4d844f3a9d3"></a>
|
|
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html#ade1bdf2529e3c58f53bfb4d844f3a9d3">MOD_LIMIT</a>   (uint64_t)1e9</td></tr>
|
|
<tr class="memdesc:ade1bdf2529e3c58f53bfb4d844f3a9d3"><td class="mdescLeft"> </td><td class="mdescRight">modulo limit <br /></td></tr>
|
|
<tr class="separator:ade1bdf2529e3c58f53bfb4d844f3a9d3"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a7a9a231e30b47bc0345749c8bd1e5077"><td class="memItemLeft" align="right" valign="top"><a id="a7a9a231e30b47bc0345749c8bd1e5077"></a>
|
|
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a>   5000</td></tr>
|
|
<tr class="memdesc:a7a9a231e30b47bc0345749c8bd1e5077"><td class="mdescLeft"> </td><td class="mdescRight">chunk size of array allocation <br /></td></tr>
|
|
<tr class="separator:a7a9a231e30b47bc0345749c8bd1e5077"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:a4441a6d27134cf3aed05727800d99456"><td class="memItemLeft" align="right" valign="top">char </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"> </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"> </td></tr>
|
|
<tr class="memitem:a7380e14d595d560007b02ce516b6b215"><td class="memItemLeft" align="right" valign="top">uint64_t </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"> </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"> </td></tr>
|
|
<tr class="memitem:a236548478af932f1115a71f601a68788"><td class="memItemLeft" align="right" valign="top">uint64_t </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"> </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"> </td></tr>
|
|
<tr class="memitem:aaf964739be92adc2f500e7da11e3f6be"><td class="memItemLeft" align="right" valign="top"><a id="aaf964739be92adc2f500e7da11e3f6be"></a>
|
|
uint64_t </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"> </td><td class="mdescRight">sum of squares of factors of numbers from 1 thru N <br /></td></tr>
|
|
<tr class="separator:aaf964739be92adc2f500e7da11e3f6be"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a3c04138a5bfe5d72780bb7e82a18e627"><td class="memItemLeft" align="right" valign="top"><a id="a3c04138a5bfe5d72780bb7e82a18e627"></a>
|
|
int </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"> </td><td class="mdescRight">Main function. <br /></td></tr>
|
|
<tr class="separator:a3c04138a5bfe5d72780bb7e82a18e627"><td class="memSeparator" colspan="2"> </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">Problem 401</a> solution - Sum of squares of divisors </p>
|
|
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kvedala">Krishna Vedala</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a7380e14d595d560007b02ce516b6b215"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a7380e14d595d560007b02ce516b6b215">◆ </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 </td>
|
|
<td class="paramname"><em>N</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">uint64_t * </td>
|
|
<td class="paramname"><em>D</em> </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"><a name="l00048"></a><span class="lineno"> 48</span> {</div>
|
|
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  uint64_t q, r;</div>
|
|
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  int64_t i, num = 0;</div>
|
|
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  </div>
|
|
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="keywordflow">if</span> (N == 1)</div>
|
|
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  {</div>
|
|
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  D[0] = 1;</div>
|
|
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  }</div>
|
|
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  </div>
|
|
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="comment">// search till sqrt(N)</span></div>
|
|
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="comment">// because after this, the pair of divisors will repeat themselves</span></div>
|
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="keywordflow">for</span> (i = 1; i * i <= N + 1; i++)</div>
|
|
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  {</div>
|
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  r = N % i; <span class="comment">// get reminder</span></div>
|
|
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  </div>
|
|
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <span class="comment">// reminder = 0 if 'i' is a divisor of 'N'</span></div>
|
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keywordflow">if</span> (r == 0)</div>
|
|
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  {</div>
|
|
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  q = N / i;</div>
|
|
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="keywordflow">if</span> (!<a class="code" 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"><a name="l00069"></a><span class="lineno"> 69</span>  {</div>
|
|
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  D[num] = i;</div>
|
|
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  num++;</div>
|
|
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  }</div>
|
|
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keywordflow">if</span> (!<a class="code" 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"><a name="l00074"></a><span class="lineno"> 74</span>  {</div>
|
|
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  D[num] = q;</div>
|
|
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  num++;</div>
|
|
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  }</div>
|
|
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  }</div>
|
|
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  </div>
|
|
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  <span class="keywordflow">if</span> (num == <a class="code" href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a>)</div>
|
|
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  { <span class="comment">// limit of array reached, allocate more space</span></div>
|
|
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  D = (uint64_t *)realloc(D, <a class="code" href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a> * <span class="keyword">sizeof</span>(uint64_t) << 1);</div>
|
|
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  }</div>
|
|
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  }</div>
|
|
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  <span class="keywordflow">return</span> num;</div>
|
|
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span> }</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="38"><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"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a4441a6d27134cf3aed05727800d99456">◆ </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 </td>
|
|
<td class="paramname"><em>N</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">uint64_t * </td>
|
|
<td class="paramname"><em>D</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">uint64_t </td>
|
|
<td class="paramname"><em>L</em> </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"><a name="l00029"></a><span class="lineno"> 29</span> {</div>
|
|
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  uint64_t i;</div>
|
|
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="../../df/db3/struct_l.html">L</a>; i++)</div>
|
|
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  {</div>
|
|
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  <span class="keywordflow">if</span> (D[i] == N)</div>
|
|
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  {</div>
|
|
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  }</div>
|
|
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  }</div>
|
|
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span> }</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a236548478af932f1115a71f601a68788"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a236548478af932f1115a71f601a68788">◆ </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 </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"><a name="l00094"></a><span class="lineno"> 94</span> {</div>
|
|
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  uint64_t sum = 0, <a class="code" href="../../df/db3/struct_l.html">L</a>;</div>
|
|
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  int64_t i;</div>
|
|
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  uint64_t *D = (uint64_t *)malloc(<a class="code" href="../../d4/d83/problem__401_2sol1_8c.html#a7a9a231e30b47bc0345749c8bd1e5077">MAX_LENGTH</a> * <span class="keyword">sizeof</span>(uint64_t));</div>
|
|
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  </div>
|
|
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <a class="code" href="../../df/db3/struct_l.html">L</a> = <a class="code" href="../../d4/d83/problem__401_2sol1_8c.html#a7380e14d595d560007b02ce516b6b215">get_divisors</a>(N, D);</div>
|
|
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keywordflow">for</span> (i = 1; i < <a class="code" href="../../df/db3/struct_l.html">L</a>; i++)</div>
|
|
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  {</div>
|
|
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  uint64_t DD = (D[i] * D[i]) % <a class="code" href="../../d4/d83/problem__401_2sol1_8c.html#ade1bdf2529e3c58f53bfb4d844f3a9d3">MOD_LIMIT</a>;</div>
|
|
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  sum += DD;</div>
|
|
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  }</div>
|
|
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  </div>
|
|
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  free(D);</div>
|
|
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  <span class="keywordflow">return</span> sum % <a class="code" href="../../d4/d83/problem__401_2sol1_8c.html#ade1bdf2529e3c58f53bfb4d844f3a9d3">MOD_LIMIT</a>;</div>
|
|
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span> }</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="38"><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 -->
|
|
<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 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 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 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>
|
|
<!-- 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="http://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|