# How to calculate $5^{2003}$ mod $13$ [duplicate]

This question already has an answer here:

How to calculate $5^{2003}$ mod $13$

using fermats little theorem

5^13-1 1 mod 13

(5^12)^166+11 mod 13

a+b modn=(a modn + b modn) modn

(1+11mod13)mod13

12 mod 13 = 12

why answer is 8 ?

how do we calculate this

thanks

## marked as duplicate by Jaideep Khare, C. Falcon, Leucippus, carmichael561, NamasteMay 21 '17 at 0:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Reducing the exponent modulo $12$ gives $5^{11}$ and because of $5^{12}\equiv 1\mod 13$ we simply have to invert $5$ modulo $13$ which easily gives $8$. – Peter May 20 '17 at 19:45
• I think the fact that you haven't written down the second line correctly is confusing you. The "$+11$" takes part in the exponent, for instance, not separate from the whole power of $5$. Write it as $5^{12\cdot 166 + 11} = (5^{12})^{166}\cdot 5^{11}$, and it should be clearer. – Arthur May 20 '17 at 19:50
• o yea so how we calculate 5^11 mod 13 ? – rektandlove May 20 '17 at 19:56
• @rektandlove By hand? Do the first three or four powers of $5$ (making use of negative representatives modulo $13$ as well as positive), and the rest should be easy. – Arthur May 20 '17 at 19:57
• alright 5^4 1 mod 13 so 11 will be 8 i got it ty – rektandlove May 20 '17 at 20:00

## 2 Answers

All modulo 13,

$$5^{2003} \equiv (5^{2})^{1001} (5)$$

$$\equiv (-1)^{1001}(5)$$

$$\equiv -5$$

$$\equiv 8$$

$5^{13-1}= 5^{12} \equiv 1 \mod 13$

$5^{2003} = 5^{12*166 +11} = (5^{12})^{166}*5^{11} \equiv 5^{11} \mod 13$

$5^{11}*5 = 5^{12}\equiv 1 \mod 13$

So if $5^{11} \equiv x \mod 13$ then $5^{11}$ is a solution to $5x \equiv 1 \mod 13$.

....

$5x \equiv 1,14,27,40 \mod 13$ so $5^{11} \equiv x\equiv 8 \equiv -5 \mod 13$.

.....

Or we could do $5^2 = 25 \equiv -1 \mod 13$ so $5^4 \equiv 1 \mod 13$ so $5^{11} \equiv 5^3 \equiv -5 \equiv 8 \mod 13$.

......

Those were trial and error. If we had to, we could use Euclid's algorithm to solve

$5x = 13k + 1$.

$5x = 10k + 3k + 1$

$5(x - 2k) = 3k + 1$. Let $v = x - 2k$

$5v = 3k + 1$

$3v + 2v = 3k + 1$

$3(v - k) + 2v = 1$ Let $w = v -k$

$3w + 2v = 1$

$w + 2(w+v) = 1$. Let $z = w+v$

$w + 2z = 1$. Let $z = 0; w = 1$

$z = w+v \implies 0 = 1 + v\implies v = -1$

$w = v-k\implies 1= - 1 -k\implies k = -2$

$v = x - 2k \implies -1 = x + 4 \implies x = -5$.

So $5^{11} \equiv x \equiv- 5 \equiv 8 \mod 13$.