Calculate the n-th number of a power with huge exponent

big numberselementary-number-theorymodular arithmeticpower series

There are several questions asked (e.g. 1, 2 or 3) on the last digit of numbers like $7^{355}$ or $237^{222222212202237}$.

My question is, if there is any efficient method to calculate the n-th digit of these numbers. To get the n-th digit, one could evaluate $7^{355} \mod 10^{n}$, but this seems not appropriate for large numbers $n$.


Example:

Calculate the second last digit (in base 10) of $237^{222222212202237}$. We calculate $237^{222222212202237} \mod 10^{2}$ and receive 69, so the answer is "6". But how would one get e.g. the thirty-first last digit?

Best Answer

The "square and reduce" method of modular exponentiation is pretty efficient. With your large numbers, it's still going to be tedious and probably impossible to do by hand. Here's a smaller example than yours, just to illustrate.

Suppose I want the 3rd last digit of $47^{57}$. So I need to reduce it mod $1000.$ Write the exponent in binary: $57 = 111001$. This shows you that $47^{57} = 47^{32}47^{16}47^{8}47^1.$ Repeatedly square $47$ and reduce mod $1000$:

$$47^1 \equiv 47 \pmod{1000}$$ $$47^2 \equiv 209 \pmod{1000}$$ $$47^4 \equiv 681 \pmod{1000}$$ $$47^8 \equiv 761 \pmod{1000}$$ $$47^{16} \equiv 121 \pmod{1000}$$ $$47^{32} \equiv 641 \pmod{1000}$$

Then $$47^{57} \equiv 47^{32}47^{16}47^{8}47^1 \equiv 641\cdot 121 \cdot 761 \cdot 47 \equiv 287 \pmod{1000}.$$

So the answer is $2$.

Related Question