You’ll normally see these kinds of digit questions on math olympiad papers. It’s a cool trick to know, but parts of it will require a calculator.

The essence of the question asked by Potatoeo is this:

How do I find the first and last digit of a really large number like 3^20?

The intended solution for this problem (particularly the part about finding the first digit of the number) required the use of the divisibility rules of 3 (a number is divisible by 3 if the sum of its digits is divisible by 3). However, I will solve this problem using a technique that works for all cases, even when divisibility rules cannot help you solve the problem.

We’ll first start with the finding the last digit of the number, because that is the easiest one to do. In order to do that, we need to first introduce the concept of *modular arithmetic*. When we use the “mod” operator, we are basically asking for the remainder of a number after division by another number (think back to your grade-school days). So, for example:

13 \equiv 1 \mod{6}\)

Once you’re comfortable with the usage of the modulo operator, you can now figure out what the last digit of that number is. Since we are only interested in the last digit of the number, we would like to eliminate any tens or more in the final answer. So, if we looked at this number mod 10, we would have our answer.

Now, here’s the cool thing about the modulo operator. Your standard rules for addition, subtraction, multiplication and integer division apply. So:

\(5 \mod{8} \times 4 \mod{8}\\ \equiv 20 \mod{8}\\ \equiv 4 \mod{8}\)Now, let’s take a look at 3^20. Let’s see what happens when we take increasing powers of 3 mod 10:

\(\begin{align*} 3^1 &\equiv 3 \mod(10)\\3^2 &\equiv 9 \mod(10)\\

3^3 &\equiv 7 \mod(10)\\

3^4 &\equiv 1 \mod(10)\\ \end{align*}\)

And we can stop here. Given that 3^4 = 1 mod (10), we can essentially “cast out” fours from the exponent, because they result in a value of 1 mod 10. So:

\(3^{20}\\=(3^4)^5\\

=(1)^5 \mod(10)\\

=1 \mod(10)\)

Therefore, the last digit of 3^20 is 1. Usually this part can be done without a calculator, so that’s a fun way to impress your friends at your next part.

Now, the slightly more difficult part: calculating the first digit of the number. In order to do this, let’s first think about what is asked of us. 3^20 is a massive number. But we’re only interested in the first digit. So, let that first digit be A. We can write this number as Axxxxxxxxx, where x’s denote other digits that we don’t care about. Pretty obvious, right? Now, let’s make one more obvious statement: 3^20 lies between A000000000 and (A+1)000000000.

Surprisingly, these two statements will help you solve problem. We first start by writing that last statement in mathematical terms:

\(\begin{alignat*}{2}A \times 10^k &\le &3^{20} &< (A+1) \times 10^k\\\log (A \times 10^k) &\le &\log(3^{20}) &< \log((A+1) \times 10^k)\\

\log (A) + \log(10^k) &\le &20\log(3) &< \log(A+1) +\log(10^k)\\

\log (A) + k\log(10) &\le & 20\log(3) &< \log(A+1) +k\log(10)\\

\log (A) + k(1) &\le & 20\log(3) &< \log(A+1) +k(1)\\

\log (A) + k &\le & 20\log(3) &< \log(A+1) +k\\

\log (A) &\le & 20\log(3) – k &< \log(A+1)\\

\end{alignat*}\)

Believe it or not, we’re almost done. The middle part of the inequality tells us that if we evaluate 20log(3) and get rid of any integer part, we will end up with a value between the logarithm of the first digit and the first digit +1. So, let’s do that:

\(20 \log(3)\\\approx 20 (0.477…)\\

\approx 9.5424…\\

\text{Taking out the integer part gives:}\\

\approx 0.5424…\\

\text{Raise 10 to the power of this:}\\

10^{0.5424}

\approx 3.49…

\)

We agreed that this number is between an integer A and A+1. So A, the first digit of 3^20 has to be 3.