mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-07-27 08:51:41 +08:00
Documentation for 341ed50da8
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<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.9.1"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.9.2"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Algorithms_in_C++: math/modular_inverse_fermat_little_theorem.cpp File Reference</title>
|
||||
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||||
@@ -17,9 +17,9 @@
|
||||
<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"],
|
||||
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>
|
||||
@@ -32,8 +32,7 @@
|
||||
<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 id="projectname">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
||||
</div>
|
||||
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
||||
</td>
|
||||
@@ -42,21 +41,22 @@
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.9.1 -->
|
||||
<!-- Generated by Doxygen 1.9.2 -->
|
||||
<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','.html');
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search",'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:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(function() {
|
||||
initMenu('../../',true,false,'search.php','Search');
|
||||
$(document).ready(function() { init_search(); });
|
||||
});
|
||||
/* @license-end */</script>
|
||||
/* @license-end */
|
||||
</script>
|
||||
<div id="main-nav"></div>
|
||||
</div><!-- top -->
|
||||
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
||||
@@ -70,7 +70,7 @@ $(function() {
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(document).ready(function(){initNavTree('d8/d53/modular__inverse__fermat__little__theorem_8cpp.html','../../'); initResizable(); });
|
||||
/* @license-end */
|
||||
</script>
|
||||
@@ -92,12 +92,11 @@ $(document).ready(function(){initNavTree('d8/d53/modular__inverse__fermat__littl
|
||||
<div class="header">
|
||||
<div class="summary">
|
||||
<a href="#func-members">Functions</a> </div>
|
||||
<div class="headertitle">
|
||||
<div class="title">modular_inverse_fermat_little_theorem.cpp File Reference</div> </div>
|
||||
<div class="headertitle"><div class="title">modular_inverse_fermat_little_theorem.cpp File Reference</div></div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
|
||||
<p>C++ Program to find the modular inverse using <a href="https://en.wikipedia.org/wiki/Fermat%27s_little_theorem">Fermat's Little Theorem</a>
|
||||
<p>C++ Program to find the modular inverse using <a href="https://en.wikipedia.org/wiki/Fermat%27s_little_theorem" target="_blank">Fermat's Little Theorem</a>
|
||||
<a href="#details">More...</a></p>
|
||||
<div class="textblock"><code>#include <iostream></code><br />
|
||||
<code>#include <vector></code><br />
|
||||
@@ -108,7 +107,7 @@ Include dependency graph for modular_inverse_fermat_little_theorem.cpp:</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
||||
Functions</h2></td></tr>
|
||||
<tr class="memitem:a4c6eefd1254eab3e8d34bf02c205e0f4"><td class="memItemLeft" align="right" valign="top">int64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d8/d53/modular__inverse__fermat__little__theorem_8cpp.html#a4c6eefd1254eab3e8d34bf02c205e0f4">binExpo</a> (int64_t a, int64_t b, int64_t m)</td></tr>
|
||||
<tr class="separator:a4c6eefd1254eab3e8d34bf02c205e0f4"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
@@ -118,8 +117,8 @@ Functions</h2></td></tr>
|
||||
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>C++ Program to find the modular inverse using <a href="https://en.wikipedia.org/wiki/Fermat%27s_little_theorem">Fermat's Little Theorem</a> </p>
|
||||
<p>Fermat's Little Theorem state that </p><p class="formulaDsp">
|
||||
<div class="textblock"><p >C++ Program to find the modular inverse using <a href="https://en.wikipedia.org/wiki/Fermat%27s_little_theorem" target="_blank">Fermat's Little Theorem</a> </p>
|
||||
<p >Fermat's Little Theorem state that </p><p class="formulaDsp">
|
||||
\[ϕ(m) = m-1\]
|
||||
</p>
|
||||
<p> where \(m\) is a prime number. </p><p class="formulaDsp">
|
||||
@@ -129,19 +128,19 @@ Functions</h2></td></tr>
|
||||
\[ a^{ϕ(m)} ≡ 1 \;\text{mod}\; m \]
|
||||
</p>
|
||||
<p> (Where '^' denotes the exponent operator)</p>
|
||||
<p>Here 'ϕ' is Euler's Totient Function. For modular inverse existence 'a' and 'm' must be relatively primes numbers. To apply Fermat's Little Theorem is necessary that 'm' must be a prime number. Generally in many competitive programming competitions 'm' is either 1000000007 (1e9+7) or 998244353.</p>
|
||||
<p>We considered m as large prime (1e9+7). \(a^{ϕ(m)} ≡ 1 \;\text{mod}\; m\) (Using Euler's Theorem) \(ϕ(m) = m-1\) using Fermat's Little Theorem. \(a^{m-1} ≡ 1 \;\text{mod}\; m\) Now multiplying both side by \(a^{-1}\). </p><p class="formulaDsp">
|
||||
<p >Here 'ϕ' is Euler's Totient Function. For modular inverse existence 'a' and 'm' must be relatively primes numbers. To apply Fermat's Little Theorem is necessary that 'm' must be a prime number. Generally in many competitive programming competitions 'm' is either 1000000007 (1e9+7) or 998244353.</p>
|
||||
<p >We considered m as large prime (1e9+7). \(a^{ϕ(m)} ≡ 1 \;\text{mod}\; m\) (Using Euler's Theorem) \(ϕ(m) = m-1\) using Fermat's Little Theorem. \(a^{m-1} ≡ 1 \;\text{mod}\; m\) Now multiplying both side by \(a^{-1}\). </p><p class="formulaDsp">
|
||||
\begin{eqnarray*} a^{m-1} \cdot a^{-1} &≡& a^{-1} \;\text{mod}\; m\\ a^{m-2} &≡& a^{-1} \;\text{mod}\; m \end{eqnarray*}
|
||||
</p>
|
||||
<p>We will find the exponent using binary exponentiation. Such that the algorithm works in \(O(\log m)\) time.</p>
|
||||
<p>Examples: -</p><ul>
|
||||
<p >We will find the exponent using binary exponentiation. Such that the algorithm works in \(O(\log m)\) time.</p>
|
||||
<p >Examples: -</p><ul>
|
||||
<li>a = 3 and m = 7</li>
|
||||
<li>\(a^{-1} \;\text{mod}\; m\) is equivalent to \(a^{m-2} \;\text{mod}\; m\)</li>
|
||||
<li>\(3^5 \;\text{mod}\; 7 = 243 \;\text{mod}\; 7 = 5\) <br />
|
||||
Hence, \(3^{-1} \;\text{mod}\; 7 = 5\) or \(3 \times 5 \;\text{mod}\; 7 = 1 \;\text{mod}\; 7\) (as \(a\times a^{-1} = 1\)) </li>
|
||||
</ul>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a4c6eefd1254eab3e8d34bf02c205e0f4"></a>
|
||||
<a id="a4c6eefd1254eab3e8d34bf02c205e0f4" name="a4c6eefd1254eab3e8d34bf02c205e0f4"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a4c6eefd1254eab3e8d34bf02c205e0f4">◆ </a></span>binExpo()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
@@ -172,24 +171,24 @@ Hence, \(3^{-1} \;\text{mod}\; 7 = 5\) or \(3 \times 5 \;\text{mod}\; 7 = 1 \;\t
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>Recursive function to calculate exponent in \(O(\log n)\) using binary exponent. </p>
|
||||
<div class="fragment"><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  {</div>
|
||||
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  a %= m;</div>
|
||||
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  int64_t res = 1;</div>
|
||||
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <span class="keywordflow">while</span> (b > 0) {</div>
|
||||
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <span class="keywordflow">if</span> (b % 2) {</div>
|
||||
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  res = res * a % m;</div>
|
||||
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  }</div>
|
||||
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  a = a * a % m;</div>
|
||||
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="comment">// Dividing b by 2 is similar to right shift.</span></div>
|
||||
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  b >>= 1;</div>
|
||||
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  }</div>
|
||||
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  <span class="keywordflow">return</span> res;</div>
|
||||
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span> }</div>
|
||||
<p >Recursive function to calculate exponent in \(O(\log n)\) using binary exponent. </p>
|
||||
<div class="fragment"><div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> {</div>
|
||||
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> a %= m;</div>
|
||||
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> int64_t res = 1;</div>
|
||||
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> <span class="keywordflow">while</span> (b > 0) {</div>
|
||||
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> <span class="keywordflow">if</span> (b % 2) {</div>
|
||||
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> res = res * a % m;</div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> }</div>
|
||||
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> a = a * a % m;</div>
|
||||
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="comment">// Dividing b by 2 is similar to right shift.</span></div>
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> b >>= 1;</div>
|
||||
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> }</div>
|
||||
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> <span class="keywordflow">return</span> res;</div>
|
||||
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span>}</div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="a09660096b134753128952246f4f4e4bd"></a>
|
||||
<a id="a09660096b134753128952246f4f4e4bd" name="a09660096b134753128952246f4f4e4bd"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a09660096b134753128952246f4f4e4bd">◆ </a></span>isPrime()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
@@ -204,23 +203,23 @@ Hence, \(3^{-1} \;\text{mod}\; 7 = 5\) or \(3 \times 5 \;\text{mod}\; 7 = 1 \;\t
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>Prime check in \(O(\sqrt{m})\) time. </p>
|
||||
<div class="fragment"><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  {</div>
|
||||
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  <span class="keywordflow">if</span> (m <= 1) {</div>
|
||||
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="keywordflow">for</span> (int64_t i = 2; i * i <= m; i++) {</div>
|
||||
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keywordflow">if</span> (m % i == 0) {</div>
|
||||
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  }</div>
|
||||
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  }</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>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span> }</div>
|
||||
<p >Prime check in \(O(\sqrt{m})\) time. </p>
|
||||
<div class="fragment"><div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> {</div>
|
||||
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> <span class="keywordflow">if</span> (m <= 1) {</div>
|
||||
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> <span class="keywordflow">for</span> (int64_t i = 2; i * i <= m; i++) {</div>
|
||||
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> <span class="keywordflow">if</span> (m % i == 0) {</div>
|
||||
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> }</div>
|
||||
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> }</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> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span>}</div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
||||
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
@@ -235,22 +234,22 @@ Hence, \(3^{-1} \;\text{mod}\; 7 = 5\) or \(3 \times 5 \;\text{mod}\; 7 = 1 \;\t
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>Main function </p>
|
||||
<div class="fragment"><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>  int64_t a, m;</div>
|
||||
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  <span class="comment">// Take input of a and m.</span></div>
|
||||
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Computing ((a^(-1))%(m)) using Fermat's Little Theorem"</span>;</div>
|
||||
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a> << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Give input 'a' and 'm' space separated : "</span>;</div>
|
||||
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a> >> a >> m;</div>
|
||||
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <span class="keywordflow">if</span> (<a class="code" href="../../d8/d53/modular__inverse__fermat__little__theorem_8cpp.html#a09660096b134753128952246f4f4e4bd">isPrime</a>(m)) {</div>
|
||||
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The modular inverse of a with mod m is (a^(m-2)) : "</span>;</div>
|
||||
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <a class="code" href="../../d8/d53/modular__inverse__fermat__little__theorem_8cpp.html#a4c6eefd1254eab3e8d34bf02c205e0f4">binExpo</a>(a, m - 2, m) << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"m must be a prime number."</span>;</div>
|
||||
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  }</div>
|
||||
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span> }</div>
|
||||
<p >Main function </p>
|
||||
<div class="fragment"><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> int64_t a, m;</div>
|
||||
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> <span class="comment">// Take input of a and m.</span></div>
|
||||
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Computing ((a^(-1))%(m)) using Fermat's Little Theorem"</span>;</div>
|
||||
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Give input 'a' and 'm' space separated : "</span>;</div>
|
||||
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a> >> a >> m;</div>
|
||||
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="../../d8/d53/modular__inverse__fermat__little__theorem_8cpp.html#a09660096b134753128952246f4f4e4bd">isPrime</a>(m)) {</div>
|
||||
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The modular inverse of a with mod m is (a^(m-2)) : "</span>;</div>
|
||||
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <a class="code hl_function" href="../../d8/d53/modular__inverse__fermat__little__theorem_8cpp.html#a4c6eefd1254eab3e8d34bf02c205e0f4">binExpo</a>(a, m - 2, m) << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> } <span class="keywordflow">else</span> {</div>
|
||||
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"m must be a prime number."</span>;</div>
|
||||
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> }</div>
|
||||
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span>}</div>
|
||||
<div class="ttc" id="abasic_istream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_istream.html">std::cin</a></div></div>
|
||||
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
||||
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
|
||||
@@ -271,7 +270,7 @@ Here is the call graph for this function:</div>
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="../../dir_296d53ceaeaa7e099814a6def439fe8a.html">math</a></li><li class="navelem"><a class="el" href="../../d8/d53/modular__inverse__fermat__little__theorem_8cpp.html">modular_inverse_fermat_little_theorem.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </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.2 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user