Solve any maths problem
Equations, derivatives, integrals, matrices, triangles, primes, statistics — or a word problem the tutor breaks into parts.
Step by step
- 5^{20} \bmod 21
Never compute the huge power. Reduce after every multiplication (repeated squaring).
- 5 \equiv 5 \pmod{21}
Reduce the base first.
- 20 = 10100_2
Write the exponent in binary: 5 squarings at most.
- 5^2 \equiv 4 \pmod{21}
Square the running power.
- 4^2 \equiv 16 \pmod{21}
Square the running power.
- r \leftarrow r \cdot 16 \equiv 16 \pmod{21}
This bit is 1: multiply the result by the current power.
- 16^2 \equiv 4 \pmod{21}
Square the running power.
- 4^2 \equiv 16 \pmod{21}
Square the running power.
- r \leftarrow r \cdot 16 \equiv 4 \pmod{21}
This bit is 1: multiply the result by the current power.
- 5^{20} \equiv 4 \pmod{21}
Done.
Reveal the answer
5^{20} \bmod 21 = 4