mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-31 17:22:27 +08:00
Documentation for a283f2a96f
This commit is contained in:
@@ -109,12 +109,17 @@ Functions</h2></td></tr>
|
||||
<tr class="memitem:afcd07701d73ed65cd616bcba02737f3d"><td class="memItemLeft" align="right" valign="top">uint64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d47/namespacemath.html#afcd07701d73ed65cd616bcba02737f3d">power</a> (uint64_t a, uint64_t b, uint64_t c)</td></tr>
|
||||
<tr class="memdesc:afcd07701d73ed65cd616bcba02737f3d"><td class="mdescLeft"> </td><td class="mdescRight">This function calculates a raised to exponent b under modulo c using modular exponentiation. <a href="../../dd/d47/namespacemath.html#afcd07701d73ed65cd616bcba02737f3d">More...</a><br /></td></tr>
|
||||
<tr class="separator:afcd07701d73ed65cd616bcba02737f3d"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a6e2dff75c5de70455b90c799d6ad6967"><td class="memTemplParams" colspan="2">template<class T > </td></tr>
|
||||
<tr class="memitem:a6e2dff75c5de70455b90c799d6ad6967"><td class="memTemplItemLeft" align="right" valign="top">T </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../dd/d47/namespacemath.html#a6e2dff75c5de70455b90c799d6ad6967">n_choose_r</a> (T n, T r)</td></tr>
|
||||
<tr class="memdesc:a6e2dff75c5de70455b90c799d6ad6967"><td class="mdescLeft"> </td><td class="mdescRight">This is the function implementation of \( \binom{n}{r} \). <a href="../../dd/d47/namespacemath.html#a6e2dff75c5de70455b90c799d6ad6967">More...</a><br /></td></tr>
|
||||
<tr class="separator:a6e2dff75c5de70455b90c799d6ad6967"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:ae1ca505751f5a6d3977b86372cfe75ea"><td class="memItemLeft" align="right" valign="top">uint64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d47/namespacemath.html#ae1ca505751f5a6d3977b86372cfe75ea">binomialCoeffSum</a> (uint64_t n)</td></tr>
|
||||
<tr class="separator:ae1ca505751f5a6d3977b86372cfe75ea"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>for <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html" title="STL class.">std::vector</a> </p>
|
||||
<p>for assert</p>
|
||||
<p>Mathematical algorithms.</p>
|
||||
<p>for io operations</p>
|
||||
<p>for assert for <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a> and <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></p>
|
||||
<p>Mathematical algorithms</p>
|
||||
@@ -122,6 +127,7 @@ Functions</h2></td></tr>
|
||||
<p>Mathematical algorithms</p>
|
||||
<p>for assert</p>
|
||||
<p>Mathematical algorithms</p>
|
||||
<p>for io operations for assert</p>
|
||||
<p>for <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a> and <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></p>
|
||||
<p>Mathematical algorithms </p>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
@@ -245,6 +251,68 @@ Functions</h2></td></tr>
|
||||
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  }</div>
|
||||
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span> }</div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="a6e2dff75c5de70455b90c799d6ad6967"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a6e2dff75c5de70455b90c799d6ad6967">◆ </a></span>n_choose_r()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
<div class="memproto">
|
||||
<div class="memtemplate">
|
||||
template<class T > </div>
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">T math::n_choose_r </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype">T </td>
|
||||
<td class="paramname"><em>n</em>, </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="paramkey"></td>
|
||||
<td></td>
|
||||
<td class="paramtype">T </td>
|
||||
<td class="paramname"><em>r</em> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>)</td>
|
||||
<td></td><td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>This is the function implementation of \( \binom{n}{r} \). </p>
|
||||
<p>We are calculating the ans with iterations instead of calculating three different factorials. Also, we are using the fact that \( \frac{n!}{r! (n-r)!} = \frac{(n - r + 1) \times \cdots \times n}{1 \times \cdots \times r} \) </p><dl class="tparams"><dt>Template Parameters</dt><dd>
|
||||
<table class="tparams">
|
||||
<tr><td class="paramname">T</td><td>Only for integer types such as long, int_64 etc </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">n</td><td>\( n \) in \( \binom{n}{r} \) </td></tr>
|
||||
<tr><td class="paramname">r</td><td>\( r \) in \( \binom{n}{r} \) </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>ans \( \binom{n}{r} \) </dd></dl>
|
||||
<div class="fragment"><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  {</div>
|
||||
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  <span class="keywordflow">if</span>(r > n / 2)</div>
|
||||
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  r = n - r; <span class="comment">// Because of the fact that nCr(n, r) == nCr(n, n - r)</span></div>
|
||||
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  T <a class="code" href="../../d7/d35/matrix__exponentiation_8cpp.html#ad8389ed58fd0ec66df248014775ad1fa">ans</a> = 1;</div>
|
||||
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 1; i <= r; i++) {</div>
|
||||
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  <a class="code" href="../../d7/d35/matrix__exponentiation_8cpp.html#ad8389ed58fd0ec66df248014775ad1fa">ans</a> *= n - r + i;</div>
|
||||
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  <a class="code" href="../../d7/d35/matrix__exponentiation_8cpp.html#ad8389ed58fd0ec66df248014775ad1fa">ans</a> /= i;</div>
|
||||
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  }</div>
|
||||
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="keywordflow">return</span> <a class="code" href="../../d7/d35/matrix__exponentiation_8cpp.html#ad8389ed58fd0ec66df248014775ad1fa">ans</a>;</div>
|
||||
<div class="line"><a name="l00042"></a><span class="lineno"> 42</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="../../dd/d47/namespacemath_a6e2dff75c5de70455b90c799d6ad6967_cgraph.svg" width="228" 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="afcd07701d73ed65cd616bcba02737f3d"></a>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<map id="math::n_choose_r" name="math::n_choose_r">
|
||||
<area shape="rect" id="node1" title="This is the function implementation of ." alt="" coords="5,5,132,32"/>
|
||||
<area shape="rect" id="node2" href="$d7/d35/matrix__exponentiation_8cpp.html#ad8389ed58fd0ec66df248014775ad1fa" title=" " alt="" coords="180,5,223,32"/>
|
||||
</map>
|
||||
@@ -0,0 +1 @@
|
||||
515b67a2cdbaa5ba6f29e970e7f43c6b
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 2.44.1 (20200629.0846)
|
||||
-->
|
||||
<!-- Title: math::n_choose_r Pages: 1 -->
|
||||
<svg width="171pt" height="28pt"
|
||||
viewBox="0.00 0.00 171.00 28.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 24)">
|
||||
<title>math::n_choose_r</title>
|
||||
<polygon fill="white" stroke="transparent" points="-4,4 -4,-24 167,-24 167,4 -4,4"/>
|
||||
<!-- Node1 -->
|
||||
<g id="node1" class="node">
|
||||
<title>Node1</title>
|
||||
<g id="a_node1"><a xlink:title="This is the function implementation of .">
|
||||
<polygon fill="#bfbfbf" stroke="black" points="0,-0.5 0,-19.5 95,-19.5 95,-0.5 0,-0.5"/>
|
||||
<text text-anchor="middle" x="47.5" y="-7.5" font-family="Helvetica,sans-Serif" font-size="10.00">math::n_choose_r</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node2 -->
|
||||
<g id="node2" class="node">
|
||||
<title>Node2</title>
|
||||
<g id="a_node2"><a xlink:href="../../d7/d35/matrix__exponentiation_8cpp.html#ad8389ed58fd0ec66df248014775ad1fa" target="_top" xlink:title=" ">
|
||||
<polygon fill="white" stroke="black" points="131,-0.5 131,-19.5 163,-19.5 163,-0.5 131,-0.5"/>
|
||||
<text text-anchor="middle" x="147" y="-7.5" font-family="Helvetica,sans-Serif" font-size="10.00">ans</text>
|
||||
</a>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Node1->Node2 -->
|
||||
<g id="edge1" class="edge">
|
||||
<title>Node1->Node2</title>
|
||||
<path fill="none" stroke="midnightblue" d="M95.25,-10C104.02,-10 112.88,-10 120.68,-10"/>
|
||||
<polygon fill="midnightblue" stroke="midnightblue" points="120.9,-13.5 130.9,-10 120.9,-6.5 120.9,-13.5"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user