Is it possible to calculate by modular algebra rules (with no calculators) numbers with powers $\textrm{mod}\ n$? Something like: $7^{127} \textrm{mod}\ 11$. If so, how it can be done? Any explanation will be apriciated!
-
See Exponentiation by squaring in Wikipédia. In your case, you can notice $7 \cdot 8 = 1 \pmod{11}$, and compute $7^{127} = 8 \cdot 7^{128} \pmod{11}$, it's a bit easier since $128=2^7$. – Jean-Claude Arbaut Apr 11 '13 at 12:52
-
thanks! but can you explain why did you multiply in 8 ? – Elior Apr 11 '13 at 12:59
-
1Here, $7$ is small, so I simply wrote $7\cdot1, 7\cdot2...$ until I found a multiple of $11$ plus $1$. Hence $8$ is the inverse of $7$ modulo $11$. For larger number, there is Extended Euclidean algorithm, used to solve Bezout's equation, which you can use to find modular inverses: solve equation $x\cdot n + y\cdot m = 1$ where $m$ is your modulus, $n$ the number to inverse, and $x$ the solution ($y$ is not useful, but you'll find it too). – Jean-Claude Arbaut Apr 11 '13 at 13:03
-
1Of course, to compute $a^b \mod m$, you don't use modular inverses usually (unless $b \lt 0$ or you compute by hand and you want to speed things up). Using a calculator or a computer, you just use the squaring algorithm, which is fast enough. – Jean-Claude Arbaut Apr 11 '13 at 13:06
-
thanks a lot! it was really helpful :) – Elior Apr 11 '13 at 13:08
-
This link is also interesting. – Jean-Claude Arbaut Apr 11 '13 at 13:14
-
@arbautjc so if I understand it well, after we get to 87^(128) and since 128 is 2^7, then we'll get (82) (mod11) and this equals 5.. right? – Elior Apr 11 '13 at 13:14
-
No, see my answer below. – Jean-Claude Arbaut Apr 11 '13 at 13:25
4 Answers
First, $$7^{127} \equiv 8 \cdot 7 \cdot 7^{127} \equiv 8 \cdot 7^{128} \equiv 8 \cdot 7^{2^7} \pmod{11}$$
Now, step by step: $$7^2 \equiv 49 \equiv 5 \pmod{11}$$ $$5^2 \equiv 25 \equiv 3 \pmod{11}$$ $$3^2 \equiv 9 \equiv -2 \pmod{11}$$ $$(-2)^2 \equiv 4 \pmod{11}$$ $$4^2 \equiv 16 \equiv 5 \pmod{11}$$ You have still two squares to compute, but you can find them already computed above: $$5^2 \equiv 25 \equiv 3 \pmod{11}$$ $$3^2 \equiv 9 \equiv -2 \pmod{11}$$
Now, we have squared $7$ times, so we have computed: $$\left(\left(\left(\left(\left(\left(7^2\right)^2\right)^2\right)^2\right)^2\right)^2\right)^2 \equiv 7^{2^7} \equiv -2 \pmod{11}$$
And finally $$7^{127} \equiv 8 \cdot 7^{128} \equiv 8 \cdot -2 \equiv -16 \equiv 6 \pmod{11}$$
- 23,277
Using Fermat's Little Theorem, $7^{10}\equiv1\pmod {11}$ as $(7,11)=1$
So, $7^{127}=(7^{10})^{12}\cdot 7^7\equiv 7^7\pmod {11}$
$7^1\equiv7 \pmod {11}, 7^2=49\equiv5, 7^4\equiv 5^2\equiv 3$ $\implies 7^7=7^1\cdot7^2\cdot7^4\equiv 7\cdot 5\cdot 3\pmod{11}\equiv105\equiv6$
- 274,582
Little Fermat $\rm\:\Rightarrow\:mod\ 11\!:\ \color{#c00}{2^{10}}\!\equiv 1\:\Rightarrow\: 7^{127}\!\equiv (-2^2)^{127}\!\equiv 2^{254}\!\equiv - 2^4 (\color{#c00}{2^{10}})^{25}\!\equiv -16\equiv 6$
Remark $\ $ For small numbers one may often employ intuition to find optimizations like this. Otherwise one may employ brute-force algorithms such as exponentiation by repeated squaring.
- 19,574
$7^3 \equiv 2 (\mod 11)$
$2^5 \equiv (-1 \mod 11) \implies7^{15} \equiv -1 \implies7^{120} \equiv1 (\mod 11)$
$7^3 \times 7^3 \times 7 \equiv 2 \times 2 \times 7 (\mod 11) \equiv11 \cdot2+6 (\mod 11)$
$7^7 \equiv 6 (\mod 11) \implies 7^{127} \equiv 6 (\mod 11)$
- 7,881