Using Fermat's little theorem to find Multiplicative Inverse












2












$begingroup$


I am new to number theory, and I was reading about using fermat's theroem to find the modular multiplicative inverse on Wikipedia here.



They wrote that by Fermat's theorem, if $m$ is prime, $a^{m-1} equiv 1text{ (mod } m)$.
Then, they wrote $a^{m-2} equiv a^{-1}text{ (mod } m)$ to find the modular inverse.
It seems as if they muliplied $a^{-1}$ to both sides. I thought $a^{-1}$ is just a notation to represent a number $x$ such that $a cdot x equiv 1 text{ (mod } m)$. How can this be multipied like that if it's just notation? It says $a^{m-2} text{ (mod } m) $ can hence be calculated by methods like binary exponentiation.










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    Note that this only works when $m$ is prime. In the general case, you have to use Euler's theorem : $$a^{varphi(m)}equiv 1mod m$$ whenever $gcd(a,m)=1$
    $endgroup$
    – Peter
    Feb 3 at 14:25












  • $begingroup$
    Worth noting $a^{-1}pmod m$ need not exist if $m$ is not prime. But IF $a^{-1}pmod m$ exists and if $a^k equiv 1 pmod m$ it would follow that $a^k*a^{-1} equiv a^{-1}pmod m$. And $a^k *a^{-1} = a^{k-1}*a*a^{-1} = a^{k-1}*1 = a^{k-1}$.
    $endgroup$
    – fleablood
    Feb 3 at 20:34
















2












$begingroup$


I am new to number theory, and I was reading about using fermat's theroem to find the modular multiplicative inverse on Wikipedia here.



They wrote that by Fermat's theorem, if $m$ is prime, $a^{m-1} equiv 1text{ (mod } m)$.
Then, they wrote $a^{m-2} equiv a^{-1}text{ (mod } m)$ to find the modular inverse.
It seems as if they muliplied $a^{-1}$ to both sides. I thought $a^{-1}$ is just a notation to represent a number $x$ such that $a cdot x equiv 1 text{ (mod } m)$. How can this be multipied like that if it's just notation? It says $a^{m-2} text{ (mod } m) $ can hence be calculated by methods like binary exponentiation.










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    Note that this only works when $m$ is prime. In the general case, you have to use Euler's theorem : $$a^{varphi(m)}equiv 1mod m$$ whenever $gcd(a,m)=1$
    $endgroup$
    – Peter
    Feb 3 at 14:25












  • $begingroup$
    Worth noting $a^{-1}pmod m$ need not exist if $m$ is not prime. But IF $a^{-1}pmod m$ exists and if $a^k equiv 1 pmod m$ it would follow that $a^k*a^{-1} equiv a^{-1}pmod m$. And $a^k *a^{-1} = a^{k-1}*a*a^{-1} = a^{k-1}*1 = a^{k-1}$.
    $endgroup$
    – fleablood
    Feb 3 at 20:34














2












2








2





$begingroup$


I am new to number theory, and I was reading about using fermat's theroem to find the modular multiplicative inverse on Wikipedia here.



They wrote that by Fermat's theorem, if $m$ is prime, $a^{m-1} equiv 1text{ (mod } m)$.
Then, they wrote $a^{m-2} equiv a^{-1}text{ (mod } m)$ to find the modular inverse.
It seems as if they muliplied $a^{-1}$ to both sides. I thought $a^{-1}$ is just a notation to represent a number $x$ such that $a cdot x equiv 1 text{ (mod } m)$. How can this be multipied like that if it's just notation? It says $a^{m-2} text{ (mod } m) $ can hence be calculated by methods like binary exponentiation.










share|cite|improve this question











$endgroup$




I am new to number theory, and I was reading about using fermat's theroem to find the modular multiplicative inverse on Wikipedia here.



They wrote that by Fermat's theorem, if $m$ is prime, $a^{m-1} equiv 1text{ (mod } m)$.
Then, they wrote $a^{m-2} equiv a^{-1}text{ (mod } m)$ to find the modular inverse.
It seems as if they muliplied $a^{-1}$ to both sides. I thought $a^{-1}$ is just a notation to represent a number $x$ such that $a cdot x equiv 1 text{ (mod } m)$. How can this be multipied like that if it's just notation? It says $a^{m-2} text{ (mod } m) $ can hence be calculated by methods like binary exponentiation.







elementary-number-theory modular-arithmetic inverse






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Feb 3 at 18:37









José Carlos Santos

164k22131235




164k22131235










asked Feb 3 at 14:10









RickRick

701215




701215








  • 1




    $begingroup$
    Note that this only works when $m$ is prime. In the general case, you have to use Euler's theorem : $$a^{varphi(m)}equiv 1mod m$$ whenever $gcd(a,m)=1$
    $endgroup$
    – Peter
    Feb 3 at 14:25












  • $begingroup$
    Worth noting $a^{-1}pmod m$ need not exist if $m$ is not prime. But IF $a^{-1}pmod m$ exists and if $a^k equiv 1 pmod m$ it would follow that $a^k*a^{-1} equiv a^{-1}pmod m$. And $a^k *a^{-1} = a^{k-1}*a*a^{-1} = a^{k-1}*1 = a^{k-1}$.
    $endgroup$
    – fleablood
    Feb 3 at 20:34














  • 1




    $begingroup$
    Note that this only works when $m$ is prime. In the general case, you have to use Euler's theorem : $$a^{varphi(m)}equiv 1mod m$$ whenever $gcd(a,m)=1$
    $endgroup$
    – Peter
    Feb 3 at 14:25












  • $begingroup$
    Worth noting $a^{-1}pmod m$ need not exist if $m$ is not prime. But IF $a^{-1}pmod m$ exists and if $a^k equiv 1 pmod m$ it would follow that $a^k*a^{-1} equiv a^{-1}pmod m$. And $a^k *a^{-1} = a^{k-1}*a*a^{-1} = a^{k-1}*1 = a^{k-1}$.
    $endgroup$
    – fleablood
    Feb 3 at 20:34








1




1




$begingroup$
Note that this only works when $m$ is prime. In the general case, you have to use Euler's theorem : $$a^{varphi(m)}equiv 1mod m$$ whenever $gcd(a,m)=1$
$endgroup$
– Peter
Feb 3 at 14:25






$begingroup$
Note that this only works when $m$ is prime. In the general case, you have to use Euler's theorem : $$a^{varphi(m)}equiv 1mod m$$ whenever $gcd(a,m)=1$
$endgroup$
– Peter
Feb 3 at 14:25














$begingroup$
Worth noting $a^{-1}pmod m$ need not exist if $m$ is not prime. But IF $a^{-1}pmod m$ exists and if $a^k equiv 1 pmod m$ it would follow that $a^k*a^{-1} equiv a^{-1}pmod m$. And $a^k *a^{-1} = a^{k-1}*a*a^{-1} = a^{k-1}*1 = a^{k-1}$.
$endgroup$
– fleablood
Feb 3 at 20:34




$begingroup$
Worth noting $a^{-1}pmod m$ need not exist if $m$ is not prime. But IF $a^{-1}pmod m$ exists and if $a^k equiv 1 pmod m$ it would follow that $a^k*a^{-1} equiv a^{-1}pmod m$. And $a^k *a^{-1} = a^{k-1}*a*a^{-1} = a^{k-1}*1 = a^{k-1}$.
$endgroup$
– fleablood
Feb 3 at 20:34










6 Answers
6






active

oldest

votes


















1












$begingroup$

They didn't "multiply" by anything. The equality $a^{m-1}equiv1$ can be written as $acdot a^{m-2}equiv1$. So, exactly as you said, $a^{m-2} $ is a number that multiplied by $a $ gives $1$.






share|cite|improve this answer









$endgroup$





















    1












    $begingroup$

    Yes, I suppose that they did multiply by $a^{-1}$ on both sides. We are working on the set$$mathbb{Z}_m^*=bigl{nin{1,2,ldots,m-1},|,gcd(n,m)=1bigr}$$here, which forms a group with respect to multiplication modulo $m$. So, if $gcd(a,m)=1$, $aequiv a'pmod m$ for some $a'inmathbb{Z}_m$ and $a'$ has an inverse in $mathbb{Z}_m^*$.






    share|cite|improve this answer









    $endgroup$





















      1












      $begingroup$

      You're right in a sense that $a^{-1}$ is a kind of notation. Now here's the thing which should clear your doubt.



      By Fermat's Little Theorem,



      $a^{m-1}equiv 1pmod{m}\$
      $Leftrightarrow a^{m-2}.aequiv 1pmod{m}$.
      Now just multiply both sides by $a^{-1}$ to get:



      $Rightarrow a^{m-2}.a.a^{-1}equiv a^{-1}pmod{m}Leftrightarrow a^{m-2}equiv a^{-1}pmod{m}$



      NOTE: It is a bit difficult to find the multiplicative inverse using FLT. You should probably try using Bezout's Identity and then Euclidean Algorithm to find the inverse as it's a bit more easier.






      share|cite|improve this answer









      $endgroup$





















        1












        $begingroup$

        Inverses are defined as you said. However, you can see that we can multiply inverses (as long as they are relatively prime to $m$) freely. Just substitute $x=a^{m-2}$ in your definition. You would receive the statement of Fermat's Little Theorem again. You can multiply and divide inverses just like you deal with other values, since you can freely multiply in modulo congruences.






        share|cite|improve this answer









        $endgroup$





















          0












          $begingroup$

          The following steps give $a^{m-2} modulo m$ :



          Determine the binary expansion of $m-2$



          Begin with x=a



          for the second till the last digit do



          square x



          if the current bit is $1$ multiply with $a$



          reduce modulo $m$



          Result : the desired residue.






          share|cite|improve this answer









          $endgroup$





















            0












            $begingroup$

            If you multiply $a$ multiplied by itself $m-1$ times by the inverse of $a$, you get.... $a$ multiplied by itself $m-2$ times and then $1$ more time and then by the inverse of $a$,... which is $a$ multiplied by itself $m-2$ times and then multiplied by $a$ times the inverse of $a$... which is $a$ multiplied by itself $m-2$ times and then multiplied by $1$ .... which is $a$ multiplied by itself $m-2$ times.



            Yes, it is notation but because of the identity nature of of $1$, the associativity of multiplication, and the meaning of the inverse, those are all legitimate results.



            $a^{m-1} equiv 1 pmod m$



            $a^{m-1}*a^{-1} equiv a^{-1} pmod m$



            $underbrace{a*a*a*...*a*a}_{m-1text{ times}}*a^{-1} equiv a^{-1} pmod m$



            $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a}_{1text {time}}*a^{-1} equiv a^{-1} pmod m$



            $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a*a^{-1}} equiv a^{-1} pmod m$



            $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace 1 equiv a^{-1} pmod m$



            $underbrace{a*a*a*...*a}_{m-2text{ times}} equiv a^{-1} pmod m$



            $a^{m-2} equiv a^{-1} pmod m$.



            ====



            Claim 1: $a^k*a^{-1} = a^{k-1}$ for any algebraic structure where $a^{-1}$ exists.



            Pf: The same as above.



            Claim 2: $(a^m)^{-1} = (a^{-1})^m$ and therefore we can define the natation $a^{-m} := (a^m)^{-1} = (a^{-1})^m$.



            Pf: $(a^m)^{-1}$ is the element $k$ where $(a^m)*k = 1$.



            And $(a^m)*(a^{-1})^m = underbrace{a*underbrace{a*underbrace{a ...*underbrace{a*a^{-1}}*... *a^{-1}}*a^{-1}}*a^{-1}}=$



            $underbrace{a*underbrace{a*underbrace{a ...*1*... *a^{-1}}*a^{-1}}*a^{-1}}=$



            $...$



            $underbrace{a*underbrace{a*underbrace{a*a^{-1}}*a^{-1}}*a^{-1}}=$



            $underbrace{a*underbrace{a*1*a^{-1}}*a^{-1}}=$



            $underbrace{a*underbrace{a*a^{-1}}*a^{-1}}=$



            $underbrace{a*1*a^{-1}}=$



            $underbrace{a*a^{-1}}=1$



            So $(a^m)^{-1} = (a^{-1})^m$.



            Claim 3:



            $a^ma^{-k} = a^{m-k}$.



            Pf: Too similar to the above to bear repeating.






            share|cite|improve this answer











            $endgroup$













              Your Answer





              StackExchange.ifUsing("editor", function () {
              return StackExchange.using("mathjaxEditing", function () {
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              });
              });
              }, "mathjax-editing");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "69"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              noCode: true, onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3098589%2fusing-fermats-little-theorem-to-find-multiplicative-inverse%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              6 Answers
              6






              active

              oldest

              votes








              6 Answers
              6






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1












              $begingroup$

              They didn't "multiply" by anything. The equality $a^{m-1}equiv1$ can be written as $acdot a^{m-2}equiv1$. So, exactly as you said, $a^{m-2} $ is a number that multiplied by $a $ gives $1$.






              share|cite|improve this answer









              $endgroup$


















                1












                $begingroup$

                They didn't "multiply" by anything. The equality $a^{m-1}equiv1$ can be written as $acdot a^{m-2}equiv1$. So, exactly as you said, $a^{m-2} $ is a number that multiplied by $a $ gives $1$.






                share|cite|improve this answer









                $endgroup$
















                  1












                  1








                  1





                  $begingroup$

                  They didn't "multiply" by anything. The equality $a^{m-1}equiv1$ can be written as $acdot a^{m-2}equiv1$. So, exactly as you said, $a^{m-2} $ is a number that multiplied by $a $ gives $1$.






                  share|cite|improve this answer









                  $endgroup$



                  They didn't "multiply" by anything. The equality $a^{m-1}equiv1$ can be written as $acdot a^{m-2}equiv1$. So, exactly as you said, $a^{m-2} $ is a number that multiplied by $a $ gives $1$.







                  share|cite|improve this answer












                  share|cite|improve this answer



                  share|cite|improve this answer










                  answered Feb 3 at 14:17









                  Martin ArgeramiMartin Argerami

                  127k1182183




                  127k1182183























                      1












                      $begingroup$

                      Yes, I suppose that they did multiply by $a^{-1}$ on both sides. We are working on the set$$mathbb{Z}_m^*=bigl{nin{1,2,ldots,m-1},|,gcd(n,m)=1bigr}$$here, which forms a group with respect to multiplication modulo $m$. So, if $gcd(a,m)=1$, $aequiv a'pmod m$ for some $a'inmathbb{Z}_m$ and $a'$ has an inverse in $mathbb{Z}_m^*$.






                      share|cite|improve this answer









                      $endgroup$


















                        1












                        $begingroup$

                        Yes, I suppose that they did multiply by $a^{-1}$ on both sides. We are working on the set$$mathbb{Z}_m^*=bigl{nin{1,2,ldots,m-1},|,gcd(n,m)=1bigr}$$here, which forms a group with respect to multiplication modulo $m$. So, if $gcd(a,m)=1$, $aequiv a'pmod m$ for some $a'inmathbb{Z}_m$ and $a'$ has an inverse in $mathbb{Z}_m^*$.






                        share|cite|improve this answer









                        $endgroup$
















                          1












                          1








                          1





                          $begingroup$

                          Yes, I suppose that they did multiply by $a^{-1}$ on both sides. We are working on the set$$mathbb{Z}_m^*=bigl{nin{1,2,ldots,m-1},|,gcd(n,m)=1bigr}$$here, which forms a group with respect to multiplication modulo $m$. So, if $gcd(a,m)=1$, $aequiv a'pmod m$ for some $a'inmathbb{Z}_m$ and $a'$ has an inverse in $mathbb{Z}_m^*$.






                          share|cite|improve this answer









                          $endgroup$



                          Yes, I suppose that they did multiply by $a^{-1}$ on both sides. We are working on the set$$mathbb{Z}_m^*=bigl{nin{1,2,ldots,m-1},|,gcd(n,m)=1bigr}$$here, which forms a group with respect to multiplication modulo $m$. So, if $gcd(a,m)=1$, $aequiv a'pmod m$ for some $a'inmathbb{Z}_m$ and $a'$ has an inverse in $mathbb{Z}_m^*$.







                          share|cite|improve this answer












                          share|cite|improve this answer



                          share|cite|improve this answer










                          answered Feb 3 at 14:18









                          José Carlos SantosJosé Carlos Santos

                          164k22131235




                          164k22131235























                              1












                              $begingroup$

                              You're right in a sense that $a^{-1}$ is a kind of notation. Now here's the thing which should clear your doubt.



                              By Fermat's Little Theorem,



                              $a^{m-1}equiv 1pmod{m}\$
                              $Leftrightarrow a^{m-2}.aequiv 1pmod{m}$.
                              Now just multiply both sides by $a^{-1}$ to get:



                              $Rightarrow a^{m-2}.a.a^{-1}equiv a^{-1}pmod{m}Leftrightarrow a^{m-2}equiv a^{-1}pmod{m}$



                              NOTE: It is a bit difficult to find the multiplicative inverse using FLT. You should probably try using Bezout's Identity and then Euclidean Algorithm to find the inverse as it's a bit more easier.






                              share|cite|improve this answer









                              $endgroup$


















                                1












                                $begingroup$

                                You're right in a sense that $a^{-1}$ is a kind of notation. Now here's the thing which should clear your doubt.



                                By Fermat's Little Theorem,



                                $a^{m-1}equiv 1pmod{m}\$
                                $Leftrightarrow a^{m-2}.aequiv 1pmod{m}$.
                                Now just multiply both sides by $a^{-1}$ to get:



                                $Rightarrow a^{m-2}.a.a^{-1}equiv a^{-1}pmod{m}Leftrightarrow a^{m-2}equiv a^{-1}pmod{m}$



                                NOTE: It is a bit difficult to find the multiplicative inverse using FLT. You should probably try using Bezout's Identity and then Euclidean Algorithm to find the inverse as it's a bit more easier.






                                share|cite|improve this answer









                                $endgroup$
















                                  1












                                  1








                                  1





                                  $begingroup$

                                  You're right in a sense that $a^{-1}$ is a kind of notation. Now here's the thing which should clear your doubt.



                                  By Fermat's Little Theorem,



                                  $a^{m-1}equiv 1pmod{m}\$
                                  $Leftrightarrow a^{m-2}.aequiv 1pmod{m}$.
                                  Now just multiply both sides by $a^{-1}$ to get:



                                  $Rightarrow a^{m-2}.a.a^{-1}equiv a^{-1}pmod{m}Leftrightarrow a^{m-2}equiv a^{-1}pmod{m}$



                                  NOTE: It is a bit difficult to find the multiplicative inverse using FLT. You should probably try using Bezout's Identity and then Euclidean Algorithm to find the inverse as it's a bit more easier.






                                  share|cite|improve this answer









                                  $endgroup$



                                  You're right in a sense that $a^{-1}$ is a kind of notation. Now here's the thing which should clear your doubt.



                                  By Fermat's Little Theorem,



                                  $a^{m-1}equiv 1pmod{m}\$
                                  $Leftrightarrow a^{m-2}.aequiv 1pmod{m}$.
                                  Now just multiply both sides by $a^{-1}$ to get:



                                  $Rightarrow a^{m-2}.a.a^{-1}equiv a^{-1}pmod{m}Leftrightarrow a^{m-2}equiv a^{-1}pmod{m}$



                                  NOTE: It is a bit difficult to find the multiplicative inverse using FLT. You should probably try using Bezout's Identity and then Euclidean Algorithm to find the inverse as it's a bit more easier.







                                  share|cite|improve this answer












                                  share|cite|improve this answer



                                  share|cite|improve this answer










                                  answered Feb 3 at 14:19









                                  Dhrubajyoti GhoshDhrubajyoti Ghosh

                                  313




                                  313























                                      1












                                      $begingroup$

                                      Inverses are defined as you said. However, you can see that we can multiply inverses (as long as they are relatively prime to $m$) freely. Just substitute $x=a^{m-2}$ in your definition. You would receive the statement of Fermat's Little Theorem again. You can multiply and divide inverses just like you deal with other values, since you can freely multiply in modulo congruences.






                                      share|cite|improve this answer









                                      $endgroup$


















                                        1












                                        $begingroup$

                                        Inverses are defined as you said. However, you can see that we can multiply inverses (as long as they are relatively prime to $m$) freely. Just substitute $x=a^{m-2}$ in your definition. You would receive the statement of Fermat's Little Theorem again. You can multiply and divide inverses just like you deal with other values, since you can freely multiply in modulo congruences.






                                        share|cite|improve this answer









                                        $endgroup$
















                                          1












                                          1








                                          1





                                          $begingroup$

                                          Inverses are defined as you said. However, you can see that we can multiply inverses (as long as they are relatively prime to $m$) freely. Just substitute $x=a^{m-2}$ in your definition. You would receive the statement of Fermat's Little Theorem again. You can multiply and divide inverses just like you deal with other values, since you can freely multiply in modulo congruences.






                                          share|cite|improve this answer









                                          $endgroup$



                                          Inverses are defined as you said. However, you can see that we can multiply inverses (as long as they are relatively prime to $m$) freely. Just substitute $x=a^{m-2}$ in your definition. You would receive the statement of Fermat's Little Theorem again. You can multiply and divide inverses just like you deal with other values, since you can freely multiply in modulo congruences.







                                          share|cite|improve this answer












                                          share|cite|improve this answer



                                          share|cite|improve this answer










                                          answered Feb 3 at 14:20









                                          HaranHaran

                                          1,116424




                                          1,116424























                                              0












                                              $begingroup$

                                              The following steps give $a^{m-2} modulo m$ :



                                              Determine the binary expansion of $m-2$



                                              Begin with x=a



                                              for the second till the last digit do



                                              square x



                                              if the current bit is $1$ multiply with $a$



                                              reduce modulo $m$



                                              Result : the desired residue.






                                              share|cite|improve this answer









                                              $endgroup$


















                                                0












                                                $begingroup$

                                                The following steps give $a^{m-2} modulo m$ :



                                                Determine the binary expansion of $m-2$



                                                Begin with x=a



                                                for the second till the last digit do



                                                square x



                                                if the current bit is $1$ multiply with $a$



                                                reduce modulo $m$



                                                Result : the desired residue.






                                                share|cite|improve this answer









                                                $endgroup$
















                                                  0












                                                  0








                                                  0





                                                  $begingroup$

                                                  The following steps give $a^{m-2} modulo m$ :



                                                  Determine the binary expansion of $m-2$



                                                  Begin with x=a



                                                  for the second till the last digit do



                                                  square x



                                                  if the current bit is $1$ multiply with $a$



                                                  reduce modulo $m$



                                                  Result : the desired residue.






                                                  share|cite|improve this answer









                                                  $endgroup$



                                                  The following steps give $a^{m-2} modulo m$ :



                                                  Determine the binary expansion of $m-2$



                                                  Begin with x=a



                                                  for the second till the last digit do



                                                  square x



                                                  if the current bit is $1$ multiply with $a$



                                                  reduce modulo $m$



                                                  Result : the desired residue.







                                                  share|cite|improve this answer












                                                  share|cite|improve this answer



                                                  share|cite|improve this answer










                                                  answered Feb 3 at 14:18









                                                  PeterPeter

                                                  48.1k1139133




                                                  48.1k1139133























                                                      0












                                                      $begingroup$

                                                      If you multiply $a$ multiplied by itself $m-1$ times by the inverse of $a$, you get.... $a$ multiplied by itself $m-2$ times and then $1$ more time and then by the inverse of $a$,... which is $a$ multiplied by itself $m-2$ times and then multiplied by $a$ times the inverse of $a$... which is $a$ multiplied by itself $m-2$ times and then multiplied by $1$ .... which is $a$ multiplied by itself $m-2$ times.



                                                      Yes, it is notation but because of the identity nature of of $1$, the associativity of multiplication, and the meaning of the inverse, those are all legitimate results.



                                                      $a^{m-1} equiv 1 pmod m$



                                                      $a^{m-1}*a^{-1} equiv a^{-1} pmod m$



                                                      $underbrace{a*a*a*...*a*a}_{m-1text{ times}}*a^{-1} equiv a^{-1} pmod m$



                                                      $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a}_{1text {time}}*a^{-1} equiv a^{-1} pmod m$



                                                      $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a*a^{-1}} equiv a^{-1} pmod m$



                                                      $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace 1 equiv a^{-1} pmod m$



                                                      $underbrace{a*a*a*...*a}_{m-2text{ times}} equiv a^{-1} pmod m$



                                                      $a^{m-2} equiv a^{-1} pmod m$.



                                                      ====



                                                      Claim 1: $a^k*a^{-1} = a^{k-1}$ for any algebraic structure where $a^{-1}$ exists.



                                                      Pf: The same as above.



                                                      Claim 2: $(a^m)^{-1} = (a^{-1})^m$ and therefore we can define the natation $a^{-m} := (a^m)^{-1} = (a^{-1})^m$.



                                                      Pf: $(a^m)^{-1}$ is the element $k$ where $(a^m)*k = 1$.



                                                      And $(a^m)*(a^{-1})^m = underbrace{a*underbrace{a*underbrace{a ...*underbrace{a*a^{-1}}*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                      $underbrace{a*underbrace{a*underbrace{a ...*1*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                      $...$



                                                      $underbrace{a*underbrace{a*underbrace{a*a^{-1}}*a^{-1}}*a^{-1}}=$



                                                      $underbrace{a*underbrace{a*1*a^{-1}}*a^{-1}}=$



                                                      $underbrace{a*underbrace{a*a^{-1}}*a^{-1}}=$



                                                      $underbrace{a*1*a^{-1}}=$



                                                      $underbrace{a*a^{-1}}=1$



                                                      So $(a^m)^{-1} = (a^{-1})^m$.



                                                      Claim 3:



                                                      $a^ma^{-k} = a^{m-k}$.



                                                      Pf: Too similar to the above to bear repeating.






                                                      share|cite|improve this answer











                                                      $endgroup$


















                                                        0












                                                        $begingroup$

                                                        If you multiply $a$ multiplied by itself $m-1$ times by the inverse of $a$, you get.... $a$ multiplied by itself $m-2$ times and then $1$ more time and then by the inverse of $a$,... which is $a$ multiplied by itself $m-2$ times and then multiplied by $a$ times the inverse of $a$... which is $a$ multiplied by itself $m-2$ times and then multiplied by $1$ .... which is $a$ multiplied by itself $m-2$ times.



                                                        Yes, it is notation but because of the identity nature of of $1$, the associativity of multiplication, and the meaning of the inverse, those are all legitimate results.



                                                        $a^{m-1} equiv 1 pmod m$



                                                        $a^{m-1}*a^{-1} equiv a^{-1} pmod m$



                                                        $underbrace{a*a*a*...*a*a}_{m-1text{ times}}*a^{-1} equiv a^{-1} pmod m$



                                                        $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a}_{1text {time}}*a^{-1} equiv a^{-1} pmod m$



                                                        $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a*a^{-1}} equiv a^{-1} pmod m$



                                                        $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace 1 equiv a^{-1} pmod m$



                                                        $underbrace{a*a*a*...*a}_{m-2text{ times}} equiv a^{-1} pmod m$



                                                        $a^{m-2} equiv a^{-1} pmod m$.



                                                        ====



                                                        Claim 1: $a^k*a^{-1} = a^{k-1}$ for any algebraic structure where $a^{-1}$ exists.



                                                        Pf: The same as above.



                                                        Claim 2: $(a^m)^{-1} = (a^{-1})^m$ and therefore we can define the natation $a^{-m} := (a^m)^{-1} = (a^{-1})^m$.



                                                        Pf: $(a^m)^{-1}$ is the element $k$ where $(a^m)*k = 1$.



                                                        And $(a^m)*(a^{-1})^m = underbrace{a*underbrace{a*underbrace{a ...*underbrace{a*a^{-1}}*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                        $underbrace{a*underbrace{a*underbrace{a ...*1*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                        $...$



                                                        $underbrace{a*underbrace{a*underbrace{a*a^{-1}}*a^{-1}}*a^{-1}}=$



                                                        $underbrace{a*underbrace{a*1*a^{-1}}*a^{-1}}=$



                                                        $underbrace{a*underbrace{a*a^{-1}}*a^{-1}}=$



                                                        $underbrace{a*1*a^{-1}}=$



                                                        $underbrace{a*a^{-1}}=1$



                                                        So $(a^m)^{-1} = (a^{-1})^m$.



                                                        Claim 3:



                                                        $a^ma^{-k} = a^{m-k}$.



                                                        Pf: Too similar to the above to bear repeating.






                                                        share|cite|improve this answer











                                                        $endgroup$
















                                                          0












                                                          0








                                                          0





                                                          $begingroup$

                                                          If you multiply $a$ multiplied by itself $m-1$ times by the inverse of $a$, you get.... $a$ multiplied by itself $m-2$ times and then $1$ more time and then by the inverse of $a$,... which is $a$ multiplied by itself $m-2$ times and then multiplied by $a$ times the inverse of $a$... which is $a$ multiplied by itself $m-2$ times and then multiplied by $1$ .... which is $a$ multiplied by itself $m-2$ times.



                                                          Yes, it is notation but because of the identity nature of of $1$, the associativity of multiplication, and the meaning of the inverse, those are all legitimate results.



                                                          $a^{m-1} equiv 1 pmod m$



                                                          $a^{m-1}*a^{-1} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a*a}_{m-1text{ times}}*a^{-1} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a}_{1text {time}}*a^{-1} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a*a^{-1}} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace 1 equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}} equiv a^{-1} pmod m$



                                                          $a^{m-2} equiv a^{-1} pmod m$.



                                                          ====



                                                          Claim 1: $a^k*a^{-1} = a^{k-1}$ for any algebraic structure where $a^{-1}$ exists.



                                                          Pf: The same as above.



                                                          Claim 2: $(a^m)^{-1} = (a^{-1})^m$ and therefore we can define the natation $a^{-m} := (a^m)^{-1} = (a^{-1})^m$.



                                                          Pf: $(a^m)^{-1}$ is the element $k$ where $(a^m)*k = 1$.



                                                          And $(a^m)*(a^{-1})^m = underbrace{a*underbrace{a*underbrace{a ...*underbrace{a*a^{-1}}*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*underbrace{a*underbrace{a ...*1*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                          $...$



                                                          $underbrace{a*underbrace{a*underbrace{a*a^{-1}}*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*underbrace{a*1*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*underbrace{a*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*1*a^{-1}}=$



                                                          $underbrace{a*a^{-1}}=1$



                                                          So $(a^m)^{-1} = (a^{-1})^m$.



                                                          Claim 3:



                                                          $a^ma^{-k} = a^{m-k}$.



                                                          Pf: Too similar to the above to bear repeating.






                                                          share|cite|improve this answer











                                                          $endgroup$



                                                          If you multiply $a$ multiplied by itself $m-1$ times by the inverse of $a$, you get.... $a$ multiplied by itself $m-2$ times and then $1$ more time and then by the inverse of $a$,... which is $a$ multiplied by itself $m-2$ times and then multiplied by $a$ times the inverse of $a$... which is $a$ multiplied by itself $m-2$ times and then multiplied by $1$ .... which is $a$ multiplied by itself $m-2$ times.



                                                          Yes, it is notation but because of the identity nature of of $1$, the associativity of multiplication, and the meaning of the inverse, those are all legitimate results.



                                                          $a^{m-1} equiv 1 pmod m$



                                                          $a^{m-1}*a^{-1} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a*a}_{m-1text{ times}}*a^{-1} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a}_{1text {time}}*a^{-1} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace{a*a^{-1}} equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}}*underbrace 1 equiv a^{-1} pmod m$



                                                          $underbrace{a*a*a*...*a}_{m-2text{ times}} equiv a^{-1} pmod m$



                                                          $a^{m-2} equiv a^{-1} pmod m$.



                                                          ====



                                                          Claim 1: $a^k*a^{-1} = a^{k-1}$ for any algebraic structure where $a^{-1}$ exists.



                                                          Pf: The same as above.



                                                          Claim 2: $(a^m)^{-1} = (a^{-1})^m$ and therefore we can define the natation $a^{-m} := (a^m)^{-1} = (a^{-1})^m$.



                                                          Pf: $(a^m)^{-1}$ is the element $k$ where $(a^m)*k = 1$.



                                                          And $(a^m)*(a^{-1})^m = underbrace{a*underbrace{a*underbrace{a ...*underbrace{a*a^{-1}}*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*underbrace{a*underbrace{a ...*1*... *a^{-1}}*a^{-1}}*a^{-1}}=$



                                                          $...$



                                                          $underbrace{a*underbrace{a*underbrace{a*a^{-1}}*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*underbrace{a*1*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*underbrace{a*a^{-1}}*a^{-1}}=$



                                                          $underbrace{a*1*a^{-1}}=$



                                                          $underbrace{a*a^{-1}}=1$



                                                          So $(a^m)^{-1} = (a^{-1})^m$.



                                                          Claim 3:



                                                          $a^ma^{-k} = a^{m-k}$.



                                                          Pf: Too similar to the above to bear repeating.







                                                          share|cite|improve this answer














                                                          share|cite|improve this answer



                                                          share|cite|improve this answer








                                                          edited Feb 3 at 20:38

























                                                          answered Feb 3 at 20:22









                                                          fleabloodfleablood

                                                          71.6k22686




                                                          71.6k22686






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Mathematics Stack Exchange!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              Use MathJax to format equations. MathJax reference.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3098589%2fusing-fermats-little-theorem-to-find-multiplicative-inverse%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Index of /

                                                              Tribalistas

                                                              Listed building