2020-06-28 23:07:29 +08:00
<!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" / >
2021-10-26 03:34:27 +08:00
< meta http-equiv = "X-UA-Compatible" content = "IE=11" / >
< meta name = "generator" content = "Doxygen 1.9.2" / >
2020-06-28 23:07:29 +08:00
< 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" >
2021-10-26 03:34:27 +08:00
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
2020-06-28 23:07:29 +08:00
});
< / 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;" >
2021-10-26 03:34:27 +08:00
< div id = "projectname" > Algorithms_in_C< span id = "projectnumber" >   1.0.0< / span >
2020-06-28 23:07:29 +08:00
< / div >
< div id = "projectbrief" > Set of algorithms implemented in C.< / div >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- end header part -->
2021-10-26 03:34:27 +08:00
<!-- Generated by Doxygen 1.9.2 -->
2020-06-28 23:07:29 +08:00
< script type = "text/javascript" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
2020-06-28 23:07:29 +08:00
/* @license-end */
< / script >
< script type = "text/javascript" src = "../../menudata.js" > < / script >
< script type = "text/javascript" src = "../../menu.js" > < / script >
< script type = "text/javascript" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2020-06-28 23:07:29 +08:00
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
2021-10-26 03:34:27 +08:00
/* @license-end */
< / script >
2020-06-28 23:07:29 +08:00
< 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" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2020-06-28 23:07:29 +08:00
$(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 >
2021-10-26 03:34:27 +08:00
< div class = "headertitle" > < div class = "title" > sol1.c File Reference< / div > < / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- header -->
< div class = "contents" >
2021-10-26 03:34:27 +08:00
< p > < a href = "https://projecteuler.net/problem=401" target = "_blank" > Problem 401< / a > solution - Sum of squares of divisors
2020-06-28 23:07:29 +08:00
< 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" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "define-members" name = "define-members" > < / a >
2020-06-28 23:07:29 +08:00
Macros< / h2 > < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:aacbb9e1f38be71e22df1584a37c56693" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "aacbb9e1f38be71e22df1584a37c56693" name = "aacbb9e1f38be71e22df1584a37c56693" > < / a >
2020-06-28 23:07:29 +08:00
#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 >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:ade1bdf2529e3c58f53bfb4d844f3a9d3" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "ade1bdf2529e3c58f53bfb4d844f3a9d3" name = "ade1bdf2529e3c58f53bfb4d844f3a9d3" > < / a >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < b > MOD_LIMIT< / b >       (uint64_t)1e9< / td > < / tr >
2020-07-17 04:36:47 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:a7a9a231e30b47bc0345749c8bd1e5077" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a7a9a231e30b47bc0345749c8bd1e5077" name = "a7a9a231e30b47bc0345749c8bd1e5077" > < / a >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < b > MAX_LENGTH< / b >       5000< / td > < / tr >
2020-07-17 04:36:47 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< / table > < table class = "memberdecls" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "func-members" name = "func-members" > < / a >
2020-06-28 23:07:29 +08:00
Functions< / h2 > < / td > < / tr >
2020-07-17 04:36:47 +08:00
< 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 >
2020-06-29 04:40:24 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a4441a6d27134cf3aed05727800d99456" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-07-17 04:36:47 +08:00
< 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 >
2020-06-29 04:40:24 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a7380e14d595d560007b02ce516b6b215" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-07-17 04:36:47 +08:00
< 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 >
2020-06-29 04:40:24 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a236548478af932f1115a71f601a68788" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:aaf964739be92adc2f500e7da11e3f6be" > < 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#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 < a href = "../../d4/d83/problem__401_2sol1_8c.html#aaf964739be92adc2f500e7da11e3f6be" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:aaf964739be92adc2f500e7da11e3f6be" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memItemLeft" align = "right" valign = "top" > 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. < a href = "../../d4/d83/problem__401_2sol1_8c.html#a3c04138a5bfe5d72780bb7e82a18e627" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table >
< a name = "details" id = "details" > < / a > < h2 class = "groupheader" > Detailed Description< / h2 >
2021-10-26 03:34:27 +08:00
< 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 >
2020-06-29 04:40:24 +08:00
< / div > < h2 class = "groupheader" > Function Documentation< / h2 >
2021-10-26 03:34:27 +08:00
< a id = "a7380e14d595d560007b02ce516b6b215" name = "a7380e14d595d560007b02ce516b6b215" > < / a >
2020-06-28 23:07:29 +08:00
< 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" >
2020-06-29 04:40:24 +08:00
< p > Get all integer divisors of a number. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
2020-06-28 23:07:29 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00048" name = "l00048" > < / a > < span class = "lineno" > 48< / span > {< / div >
< div class = "line" > < a id = "l00049" name = "l00049" > < / a > < span class = "lineno" > 49< / span > uint64_t q, r;< / div >
< div class = "line" > < a id = "l00050" name = "l00050" > < / a > < span class = "lineno" > 50< / span > int64_t i, num = 0;< / div >
< div class = "line" > < a id = "l00051" name = "l00051" > < / a > < span class = "lineno" > 51< / span > < / div >
< div class = "line" > < a id = "l00052" name = "l00052" > < / a > < span class = "lineno" > 52< / span > < span class = "keywordflow" > if< / span > (N == 1)< / div >
< div class = "line" > < a id = "l00053" name = "l00053" > < / a > < span class = "lineno" > 53< / span > {< / div >
< div class = "line" > < a id = "l00054" name = "l00054" > < / a > < span class = "lineno" > 54< / span > D[0] = 1;< / div >
< div class = "line" > < a id = "l00055" name = "l00055" > < / a > < span class = "lineno" > 55< / span > < span class = "keywordflow" > return< / span > 1;< / div >
< div class = "line" > < a id = "l00056" name = "l00056" > < / a > < span class = "lineno" > 56< / span > }< / div >
< div class = "line" > < a id = "l00057" name = "l00057" > < / a > < span class = "lineno" > 57< / span > < / div >
< div class = "line" > < a id = "l00058" name = "l00058" > < / a > < span class = "lineno" > 58< / span > < span class = "comment" > // search till sqrt(N)< / span > < / div >
< div class = "line" > < a id = "l00059" 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 id = "l00060" 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 id = "l00061" name = "l00061" > < / a > < span class = "lineno" > 61< / span > {< / div >
< div class = "line" > < a id = "l00062" name = "l00062" > < / a > < span class = "lineno" > 62< / span > r = N % i; < span class = "comment" > // get reminder< / span > < / div >
< div class = "line" > < a id = "l00063" name = "l00063" > < / a > < span class = "lineno" > 63< / span > < / div >
< div class = "line" > < a id = "l00064" 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 id = "l00065" name = "l00065" > < / a > < span class = "lineno" > 65< / span > < span class = "keywordflow" > if< / span > (r == 0)< / div >
< div class = "line" > < a id = "l00066" name = "l00066" > < / a > < span class = "lineno" > 66< / span > {< / div >
< div class = "line" > < a id = "l00067" name = "l00067" > < / a > < span class = "lineno" > 67< / span > q = N / i;< / div >
< div class = "line" > < a id = "l00068" name = "l00068" > < / a > < 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" > < a id = "l00069" name = "l00069" > < / a > < span class = "lineno" > 69< / span > {< / div >
< div class = "line" > < a id = "l00070" name = "l00070" > < / a > < span class = "lineno" > 70< / span > D[num] = i;< / div >
< div class = "line" > < a id = "l00071" name = "l00071" > < / a > < span class = "lineno" > 71< / span > num++;< / div >
< div class = "line" > < a id = "l00072" name = "l00072" > < / a > < span class = "lineno" > 72< / span > }< / div >
< div class = "line" > < a id = "l00073" name = "l00073" > < / a > < 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" > < a id = "l00074" name = "l00074" > < / a > < span class = "lineno" > 74< / span > {< / div >
< div class = "line" > < a id = "l00075" name = "l00075" > < / a > < span class = "lineno" > 75< / span > D[num] = q;< / div >
< div class = "line" > < a id = "l00076" name = "l00076" > < / a > < span class = "lineno" > 76< / span > num++;< / div >
< div class = "line" > < a id = "l00077" name = "l00077" > < / a > < span class = "lineno" > 77< / span > }< / div >
< div class = "line" > < a id = "l00078" name = "l00078" > < / a > < span class = "lineno" > 78< / span > }< / div >
< div class = "line" > < a id = "l00079" name = "l00079" > < / a > < span class = "lineno" > 79< / span > < / div >
< div class = "line" > < a id = "l00080" name = "l00080" > < / a > < 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" > < a id = "l00081" name = "l00081" > < / a > < span class = "lineno" > 81< / span > { < span class = "comment" > // limit of array reached, allocate more space< / span > < / div >
< div class = "line" > < a id = "l00082" name = "l00082" > < / a > < 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) < < 1);< / div >
< div class = "line" > < a id = "l00083" name = "l00083" > < / a > < span class = "lineno" > 83< / span > }< / div >
< div class = "line" > < a id = "l00084" name = "l00084" > < / a > < span class = "lineno" > 84< / span > }< / div >
< div class = "line" > < a id = "l00085" name = "l00085" > < / a > < span class = "lineno" > 85< / span > < span class = "keywordflow" > return< / span > num;< / div >
< div class = "line" > < a id = "l00086" name = "l00086" > < / a > < span class = "lineno" > 86< / span > }< / div >
2021-02-06 03:52:57 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
2021-10-26 03:34:27 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d4/d83/problem__401_2sol1_8c_a7380e14d595d560007b02ce516b6b215_cgraph.svg" width = "202" height = "38" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2020-06-28 23:07:29 +08:00
< / div >
< / div >
< / div >
< / div >
2021-10-26 03:34:27 +08:00
< a id = "a4441a6d27134cf3aed05727800d99456" name = "a4441a6d27134cf3aed05727800d99456" > < / a >
2020-06-28 23:07:29 +08:00
< 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" >
2020-06-29 04:40:24 +08:00
< p > Check if a number is present in given array. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
2020-06-28 23:07:29 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00029" name = "l00029" > < / a > < span class = "lineno" > 29< / span > {< / div >
< div class = "line" > < a id = "l00030" name = "l00030" > < / a > < span class = "lineno" > 30< / span > uint64_t i;< / div >
< div class = "line" > < a id = "l00031" name = "l00031" > < / a > < span class = "lineno" > 31< / span > < span class = "keywordflow" > for< / span > (i = 0; i < < a class = "code hl_struct" href = "../../df/db3/struct_l.html" > L< / a > ; i++)< / div >
< div class = "line" > < a id = "l00032" name = "l00032" > < / a > < span class = "lineno" > 32< / span > {< / div >
< div class = "line" > < a id = "l00033" name = "l00033" > < / a > < span class = "lineno" > 33< / span > < span class = "keywordflow" > if< / span > (D[i] == N)< / div >
< div class = "line" > < a id = "l00034" name = "l00034" > < / a > < span class = "lineno" > 34< / span > {< / div >
< div class = "line" > < a id = "l00035" name = "l00035" > < / a > < span class = "lineno" > 35< / span > < span class = "keywordflow" > return< / span > 1;< / div >
< div class = "line" > < a id = "l00036" name = "l00036" > < / a > < span class = "lineno" > 36< / span > }< / div >
< div class = "line" > < a id = "l00037" name = "l00037" > < / a > < span class = "lineno" > 37< / span > }< / div >
< div class = "line" > < a id = "l00038" name = "l00038" > < / a > < span class = "lineno" > 38< / span > < span class = "keywordflow" > return< / span > 0;< / div >
< div class = "line" > < a id = "l00039" name = "l00039" > < / a > < span class = "lineno" > 39< / span > }< / div >
2021-02-06 03:52:57 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
2021-10-26 03:34:27 +08:00
< a id = "a3c04138a5bfe5d72780bb7e82a18e627" name = "a3c04138a5bfe5d72780bb7e82a18e627" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a3c04138a5bfe5d72780bb7e82a18e627" > ◆ < / 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  < / td >
< td class = "paramname" > < em > argc< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > char **  < / td >
< td class = "paramname" > < em > argv< / em >   < / 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" > < a id = "l00133" name = "l00133" > < / a > < span class = "lineno" > 133< / span > {< / div >
< div class = "line" > < a id = "l00134" name = "l00134" > < / a > < span class = "lineno" > 134< / span > uint64_t N = 1000;< / div >
< div class = "line" > < a id = "l00135" name = "l00135" > < / a > < span class = "lineno" > 135< / span > < / div >
< div class = "line" > < a id = "l00136" name = "l00136" > < / a > < span class = "lineno" > 136< / span > < span class = "keywordflow" > if< / span > (argc == 2)< / div >
< div class = "line" > < a id = "l00137" name = "l00137" > < / a > < span class = "lineno" > 137< / span > {< / div >
< div class = "line" > < a id = "l00138" name = "l00138" > < / a > < span class = "lineno" > 138< / span > N = strtoll(argv[1], NULL, 10);< / div >
< div class = "line" > < a id = "l00139" name = "l00139" > < / a > < span class = "lineno" > 139< / span > }< / div >
< div class = "line" > < a id = "l00140" name = "l00140" > < / a > < span class = "lineno" > 140< / span > < span class = "keywordflow" > else< / span > < span class = "keywordflow" > if< / span > (argc > 2)< / div >
< div class = "line" > < a id = "l00141" name = "l00141" > < / a > < span class = "lineno" > 141< / span > {< / div >
< div class = "line" > < a id = "l00142" name = "l00142" > < / a > < span class = "lineno" > 142< / span > fprintf(stderr, < span class = "stringliteral" > " Wrong number of input arguments!\n" < / span > );< / div >
< div class = "line" > < a id = "l00143" name = "l00143" > < / a > < span class = "lineno" > 143< / span > printf(< span class = "stringliteral" > " Usage:\t ./sol1.c [N=1000]" < / span > );< / div >
< div class = "line" > < a id = "l00144" name = "l00144" > < / a > < span class = "lineno" > 144< / span > < span class = "keywordflow" > return< / span > -1;< / div >
< div class = "line" > < a id = "l00145" name = "l00145" > < / a > < span class = "lineno" > 145< / span > }< / div >
< div class = "line" > < a id = "l00146" name = "l00146" > < / a > < span class = "lineno" > 146< / span > < / div >
< div class = "line" > < a id = "l00147" name = "l00147" > < / a > < span class = "lineno" > 147< / span > clock_t start_time = clock();< / div >
< div class = "line" > < a id = "l00148" name = "l00148" > < / a > < 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" > < a id = "l00149" name = "l00149" > < / a > < span class = "lineno" > 149< / span > < span class = "keywordtype" > double< / span > dtime = clock() - start_time;< / div >
< div class = "line" > < a id = "l00150" name = "l00150" > < / a > < span class = "lineno" > 150< / span > < / div >
< div class = "line" > < a id = "l00151" name = "l00151" > < / a > < span class = "lineno" > 151< / span > printf(< span class = "stringliteral" > " N = %" < / span > PRIu64 < span class = "stringliteral" > " \nSum: %" < / span > PRIu64 < span class = "stringliteral" > " \n" < / span > , N, result);< / div >
< div class = "line" > < a id = "l00152" name = "l00152" > < / a > < span class = "lineno" > 152< / span > printf(< span class = "stringliteral" > " Time taken: %.4gms\n" < / span > , dtime * 1e3 / CLOCKS_PER_SEC);< / div >
< div class = "line" > < a id = "l00153" name = "l00153" > < / a > < span class = "lineno" > 153< / span > < / div >
< div class = "line" > < a id = "l00154" name = "l00154" > < / a > < span class = "lineno" > 154< / span > < span class = "keywordflow" > return< / span > 0;< / div >
< div class = "line" > < a id = "l00155" name = "l00155" > < / a > < 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 = "519" 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 = "aaf964739be92adc2f500e7da11e3f6be" name = "aaf964739be92adc2f500e7da11e3f6be" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#aaf964739be92adc2f500e7da11e3f6be" > ◆ < / 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  < / 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" > < a id = "l00115" name = "l00115" > < / a > < span class = "lineno" > 115< / span > {< / div >
< div class = "line" > < a id = "l00116" name = "l00116" > < / a > < span class = "lineno" > 116< / span > uint64_t s, sum = 0;< / div >
< div class = "line" > < a id = "l00117" name = "l00117" > < / a > < span class = "lineno" > 117< / span > int64_t i;< / div >
< div class = "line" > < a id = "l00118" name = "l00118" > < / a > < span class = "lineno" > 118< / span > < / div >
< div class = "line" > < a id = "l00119" name = "l00119" > < / a > < span class = "lineno" > 119< / span > < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a id = "l00120" name = "l00120" > < / a > < span class = "lineno" > 120< / span > < span class = "comment" > // parallelize on threads< / span > < / div >
< div class = "line" > < a id = "l00121" name = "l00121" > < / a > < span class = "lineno" > 121< / span > < span class = "preprocessor" > #pragma omp parallel for reduction(+ : sum)< / span > < / div >
< div class = "line" > < a id = "l00122" name = "l00122" > < / a > < span class = "lineno" > 122< / span > < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a id = "l00123" name = "l00123" > < / a > < span class = "lineno" > 123< / span > < span class = "keywordflow" > for< / span > (i = 0; i < = N; i++)< / div >
< div class = "line" > < a id = "l00124" name = "l00124" > < / a > < span class = "lineno" > 124< / span > {< / div >
< div class = "line" > < a id = "l00125" name = "l00125" > < / a > < 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" > < a id = "l00126" name = "l00126" > < / a > < span class = "lineno" > 126< / span > sum += s;< / div >
< div class = "line" > < a id = "l00127" name = "l00127" > < / a > < span class = "lineno" > 127< / span > }< / div >
< div class = "line" > < a id = "l00128" name = "l00128" > < / a > < 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" > < a id = "l00129" name = "l00129" > < / a > < 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 = "420" 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 = "a236548478af932f1115a71f601a68788" name = "a236548478af932f1115a71f601a68788" > < / a >
2020-06-28 23:07:29 +08:00
< 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" >
2020-06-29 04:40:24 +08:00
< p > compute sum of squares of all integer factors of a number < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
2020-06-28 23:07:29 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00094" name = "l00094" > < / a > < span class = "lineno" > 94< / span > {< / div >
< div class = "line" > < a id = "l00095" name = "l00095" > < / a > < 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" > < a id = "l00096" name = "l00096" > < / a > < span class = "lineno" > 96< / span > int64_t i;< / div >
< div class = "line" > < a id = "l00097" name = "l00097" > < / a > < 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" > < a id = "l00098" name = "l00098" > < / a > < span class = "lineno" > 98< / span > < / div >
< div class = "line" > < a id = "l00099" name = "l00099" > < / a > < 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" > < a id = "l00100" name = "l00100" > < / a > < span class = "lineno" > 100< / span > < span class = "keywordflow" > for< / span > (i = 1; i < < a class = "code hl_struct" href = "../../df/db3/struct_l.html" > L< / a > ; i++)< / div >
< div class = "line" > < a id = "l00101" name = "l00101" > < / a > < span class = "lineno" > 101< / span > {< / div >
< div class = "line" > < a id = "l00102" name = "l00102" > < / a > < 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" > < a id = "l00103" name = "l00103" > < / a > < span class = "lineno" > 103< / span > sum += DD;< / div >
< div class = "line" > < a id = "l00104" name = "l00104" > < / a > < span class = "lineno" > 104< / span > }< / div >
< div class = "line" > < a id = "l00105" name = "l00105" > < / a > < span class = "lineno" > 105< / span > < / div >
< div class = "line" > < a id = "l00106" name = "l00106" > < / a > < 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" > < a id = "l00107" name = "l00107" > < / a > < 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" > < a id = "l00108" name = "l00108" > < / a > < span class = "lineno" > 108< / span > }< / div >
2021-02-18 06:41:16 +08:00
< 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 >
2021-02-06 03:52:57 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
2021-10-26 03:34:27 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d4/d83/problem__401_2sol1_8c_a236548478af932f1115a71f601a68788_cgraph.svg" width = "315" height = "38" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2020-06-28 23:07:29 +08:00
< / 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 >
2021-10-26 03:34:27 +08:00
< 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.2 < / li >
2020-06-28 23:07:29 +08:00
< / ul >
< / div >
< / body >
< / html >