What is the *middle* digit of $3^{100000}$?
The decimal representation of $3^{100000}$ has $47713$ digits. What is the $23857^{th}$ digit - i.e. the one in the $10^{23856}$'s place?
There are lots of questions on this site asking for the last digit of various large exponents, which are well handled by modular arithmetic. The last digit of $3^{100000}$ is $1$ by such methods. There are some fewer number of questions asking for the first digit of a number, which can be handled by considering the fractional part of the base ten logarithm of the number. The first digit of the number is $1$.
Either method can be modified to give the first few or last few digits, but they don't generalize well beyond that, and there's no obvious way to combine the methods.
Is there a method to find arbitrary digits of small integers raised to large ones? Is there any reason to suspect that computing a digit in the middle is, in terms of computational complexity, a more difficult problem than computing digits on the edge?
Solution 1:
In contrast with other programming languages from its time, Pascal (the programming language) also supports a set type, implemented as a bit pattern. The bit patterns associated with the Pascal set type are $256$ bits wide, but this limitation is not essential and can been replaced with other (larger) values eventually. See Wikipedia for a reference. A rather detailed description of the set type implementation can be found as well . So we have the following practice:
- a bit pattern in a computer is a set type
- a bit pattern in a computer is a natural number type
More precisely: the hereditarily finite sets are in one-to-one correspondence with the natural numbers. And the latter fact is independent of computers.
Examples. $$ \begin{array}{l} 0 = 000 = \{\} \\ 1 = 001 = \{0\} = \{\{\}\} \\ 2 = 010 = \{1\} = \{\{\{\}\}\} \\ 3 = 011 = \{0\; 1\} = \{\{\}\{\{\}\}\} \\ 4 = 100 = \{2\} = \{\{\{\{\}\}\}\} \\ 5 = 101 = \{0\; 2\} = \{\{\}\{\{\{\}\}\}\} \\ 6 = 110 = \{1\; 2\} = \{\{\{\}\}\{\{\{\}\}\}\} \\ 7 = 111 = \{0\; 1\; 2\} = \{\{\}\{\{\}\}\{\{\{\}\}\}\} \\ \cdots \end{array} $$ The above is related to the following reference, by Alexander Abian and Samuel LaMacchia:
If the curly brackets $\{\}$ are replaced by square brackets $\left[\,\right]$ then another important fact is observed:
- a set type is is a natural number type is a sorted natural numbers array type
-
Meelo.dpr
drie5.txt
47713 1 2 1So, indeed, as Lucian says in a comment: it's "obvious" that the digit in the middle is a $\large\, 2$ .
Note. A power like $\,3^{100000}\,$ sounds quite impressive, but with a smart algorithm, the number of operations is only $\,\ln_2(100000)\approx17$ . For real numbers $\,x\,$ and a natural $\,n\,$ it goes as follows:
function power(x : double; n : integer) : double; var m : integer; p, y : double; begin m := n; y := x; p := 1; while m > 0 do begin if (m and 1) > 0 then p := p * y; m := m shr 1; { m := m / 2 } y := y * y; end; power := p; end;Wikipedia reference: Efficient computation with integer exponents .
BONUS. In view of the above, the following answer is interesting:
-
The purpose of the $\sf ZFC$ Axiom of Infinity
It was observed in 1937 by Ackermann [1] that $\mathbb{N}$ with the membership relation defined by
$n \in m$ iff the $n$th digit in the binary representation of $m$ is $1$
satisfies ZF$-$inf. This interpretation, formalized in ZF with $\omega$ in place of $\mathbb{N}$ yields a bijection between $\omega$ and the collection $V_\omega$ of hereditarily finite sets.
Solution 2:
I wondered how Lucian could come to the correct result within one hour after the question appeared. So I gave Mathematica a chance. Here is the output: