0

I know from Fermat's little theorem that $a^{m-1}\bmod m \equiv 1\pmod m $ when $m$ is prime number.

But I don't understand how we got $ a^n\bmod m = a^{n\bmod (m-1)}\bmod m $ from Fermat's little theorem when $m$ is a prime number.

Bill Dubuque
  • 272,048
Ryzer
  • 3
  • 3
    Well, $a^{n+k(m-1)}\equiv a^n\times a^{k(m-1)}\equiv a^n\times \left( a^{m-1}\right)^k\equiv a^n\pmod m$ – lulu Apr 11 '21 at 09:50
  • I really don't understand why mod (m-1) is in the exponent. For me mod (m-1) just indicates the ring you are working with. – DaifM Apr 11 '21 at 11:21
  • @DaifM bigmod(a,n,m) == bigmod(a,n%(m-1), m), where bigmod(a,n,m) computes $a^n mod m$, I wanted to know why both side gives same result. And yes mod(m-1) is in the exponent applied on $n$ but you seem to be misunderstood that $mod m$ is in the right side also. – Ryzer Apr 11 '21 at 11:46
  • See the Corollary in the linked dupe. Or proved directly: $$\large r=n\bmod{p!-!1}\Rightarrow n = r+q(p!-!1)\Rightarrow a^n = a^r (\color{#c00}{a^{p-1}})^q\equiv a^r\color{#c00}{1}^q\equiv a^r\pmod{p}$$ – Bill Dubuque Apr 11 '21 at 15:03
  • Your mod expressions seem to imply you should learn more about the distinction between mod as an operator vs. congruence relation, e.g. see here – Bill Dubuque Apr 11 '21 at 15:44
  • See also here for basic rules of conguence / modular arithmetic. In my first comment we used the Power & Product Rules. – Bill Dubuque Apr 11 '21 at 15:55
  • If $a^{m-1} \equiv 1 \pmod m$ (which is true if and only if $m\not \mid a$; you left that part out) then for any natural $k$ we have $a^{k(m-1)}\equiv (a^{m-1})^k \equiv 1^k \equiv 1 \pmod m$. So for any $n$ then $a^{n+k(m-1)}=a^n\cdot a^{k(m-1)}\equiv a^n\cdot 1 \equiv a^n \pmod {m-1}$. So if $n \equiv n'\pmod {m-1}$ then $n= n'+k(m-1)$ for some integer $k$ so $a^n\equiv a^{n'}\pmod m$. – fleablood Apr 11 '21 at 16:14

1 Answers1

0

By Fermat's little theorem $a^{\,p-1}\ (\bmod p\ ) = 1$ when $p\in \mathbb{P}$. Therefore when computing $a^b\ (\bmod p\ )$ when $p\in \mathbb{P}$ and $b>p-1$, the exponent $b$ can be reduced $(\bmod(p-1)\ )$ as follows: $a^b\ (\bmod p\ )=a^{b\ (\bmod(p-1)\ )}\ (\bmod p\ )$.

For example assume $b=k\,(p-1)+c$ where $k>0$ and $p\in \mathbb{P}$. Then $a^b\ (\bmod p\ )=a^{k\,(p-1)+c}\ (\bmod p\ )=(a^{p-1})^k\,a^c\ (\bmod p\ )=1^k\,a^c\ (\bmod p\ )=a^c\ (\bmod p\ )$ where $c=b\ (\bmod(p-1)\ )$.

Steven Clark
  • 7,363