-1

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?

Peter
  • 84,454
  • 2
    You seem to mean the $n^{th}$ last digit, for which modular arithmetic seems to be the answer (values are periodic). If you were to mean the $n^{th}$ most significant digit, the standard answer would be sufficiently accurate logarithms. – Mark Bennet Mar 07 '22 at 09:04
  • Thanks for your comment, i addressed it by providing an example. – skoestlmeier Mar 07 '22 at 10:03
  • A little brute force finds that $237^{20} \equiv 1\bmod 100$, and $2222222\dots 237 \equiv 17 \bmod 20$. Thus $237^{2222222\dots 237} \equiv 237^{17} \bmod 100$, and finally $237^{2222222\dots 237} \equiv 17 \bmod 100$, not $69$. – Peter Phipps Mar 07 '22 at 15:58

1 Answers1

2

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$.

  • 1
    This doesn't seem to answer the question (probably because this was posted before the question was edited to include an example). – Snaw Mar 08 '22 at 11:10
  • 1
    @Snaw The question was "is there an efficient method." I gave a method that is $O(\ln n)$. Pretty efficient. So who knows what you're talking about. – B. Goddard Mar 08 '22 at 11:37
  • 1
    I'm referring to "But how would one get e.g. the thirty-first last digit?". I'm not saying there's a better answer-- only that there is no way to do what OP is asking for by hand (as far as I know). – Snaw Mar 08 '22 at 12:39
  • 1
    @Snaw He didn't say "by hand." He said "efficient." – B. Goddard Mar 08 '22 at 20:29