# Sum of digits of sum of digits of sum of digits of $7^{7^{7^7}}$

On the back of a mathematical magazine, I came across some "quick facts" about the number 7. Most of them were real life related ones, like "Rome was buit on 7 hills", "the neck of most mamals is made out of 7 bones", "a ladybird has 7 black spots on its back" etc.

But the last one was very intriguing: denote by $A$ the sum of digits of the number $7^{7^{7^7}}$, by $B$ the sum of digits of $A$, and by $C$ the sum of digits of $B$. What is the sum of digits of $C$?

After doing some research on the power of usual computers, I concluded that it would not be possible to calculculate this number and find the sums like this. So the solution must be pure mathematical. But I could not manage to find any path to a solution. If it helps, we have that $7^7=823543$ which has sum of digits $25$, but online big number calculators can't even compute $7^{7^7}$, and I figured it was not worth it to write such a program myself.

Edit: After some good hours I want to draw some conclusions about the question as well as proposing some extensions.

We saw that for the proposed number $^4 7$, the searched sum is $7$. Mees de Vries found a rigorous proof for that, but which doesn't seem to work in a general case; Henry gave a quite tedious solution which may be generalizable with some extra explanations needed, and Gottfried Helms came up with a computer algorithm which he used to deduce that the sum of digits (repeated as many times as necessary) will repeat with period 3 across consecutive powers of 7.

Now, based on the fact that from Euler's Theorem we will get that $^n 7$ has residue $7$ mod 9, for any $n\in\mathbb{N}^*$, I came to believe that if we repeatedly do sum of digits for larger $^n 7$ we will also get 7. The question is how many times we would have to do the sum-of-digits. Also, I would like to notice that the number 7 here is not a simple coincidence. It is because it is $\varphi(9)+1$, and the sum-of-digits conserves mod 9. It would be interesting to find a similar property for 3, which has totient function 2, and also "conserves" the residue of the sum-of-digits (here it seems that the sum will be 9 - at least this is how it is for $3^3$ and $3^{3^3}$).

• I am almost certain the proof is going to come down to the fact that applying the sum-of-digits operation to ${}^47$ four times is going to result in a 1-digit number, so the answer is just the positive single-digit equivalent mod 9. But it is hard to prove because the sum-of-digits operation isn't very well-behaved. – Mees de Vries Jul 25 '18 at 10:24
• Also it is pretty hard just to find the residue mod 9 of that number – Andrew V Jul 25 '18 at 10:27
• No, that would definitely be the easy part. – Mees de Vries Jul 25 '18 at 10:28
• Alright, now I really expect the answer to be 7 or something similar – Andrew V Jul 25 '18 at 10:30
• apropos "big numbers" - have you tried Robert Munafo's "hypercalc"? It can do some nice things with really large numbers... (see mrob.com/pub/comp/hypercalc/hypercalc-javascript.html) – Gottfried Helms Jul 25 '18 at 13:14

Let $\mathrm{sod}$ stand for the upper-bounded sum-of-digits operation, that is, $$\mathrm{sod}(n) = \sup_{m \leq n}\left( \text{sum of digits of m}\right).$$ This has the nice advantage that it is trivially a monotone function.

If we can prove that $$\mathrm{sod}^4\left(7^{7^{7^7}}\right) < 10,$$ we can use Euler's theorem to quickly conclude, because applying the (ordinary) sum of digits operation does not change the residue modulo 9. But let's let WolframAlpha do the work for us, to see that the result will be 7.

Note that $\mathrm{sod}(n) \leq 9(\log_{10}(n) + 1)$, as $\log_{10}(n) + 1$ is an upper bound on the number of digits in the number $n$, and each digit is at most 9. Let's focus on the case where $n$ has at least two digits, so that in fact this is upper bounded by $18\log_{10}(n)$. Then we have that $$\mathrm{sod}^4\left(7^{7^{7^7}}\right) \leq \mathrm{sod}^3\left(7^{7^7} \cdot 18 \cdot \log_{10}(7)\right) \leq \mathrm{sod}^2\left(7^7\cdot 18 \cdot \log_{10}(7) + 18\log_{10}(18) + 18\log_{10}^2(7)\right).$$ (Note that we are using the monotonicity of our $\mathrm{sod}$ function here! This is why we made the definition.)

The number in the argument of $\mathrm{sod}^2$ is small enough that we can just evaluate it for simplicity: it is certainly upper bounded by 12527573. The $\mathrm{sod}$ of this number is the sum of digits of $9999999$, which is $7 \times 9 = 63$, and we are left just barely (!) able to conclude, because the $\mathrm{sod}$ of this number is the sum of digits of $59$, which is $14$. Despite the fact that this is larger than the 10 we claimed we needed above, we are still done: if the sum of digits we were after were greater than 7 it would have to be at least 16, and it cannot be, thus we conclude that the result is indeed 7.

• This is pretty amazing. How did you come across the sod function? – Andrew V Jul 25 '18 at 11:07
• I made it up -- I needed something that would upper bound the sum-of-digits operation while still being monotone (because when you can't use arguments of the form $a \leq b \implies \mathrm{sod}(a) \leq \mathrm{sod}(b)$ the proof falls apart). – Mees de Vries Jul 25 '18 at 11:09
• Going straight to the $18\log_{10}(n)$ would have worked for the first part of the proof, but it wouldn't have been tight enough for the correct conclusion. – Mees de Vries Jul 25 '18 at 11:11
• I was wondering if larger numbers like $^5 7$ would still have the quadruple (or quintuple) sum 7, since the residue mod 9 is still 7. I tried you method, but if you apply the inequality $\text{sod}(n)\leq 18\log_{10} n$ too many times, you won't be able able to compute the result anymore, since you will have the logarithm of a sum after 3 steps. – Andrew V Jul 25 '18 at 18:46
• @AndreiCataron, it's hard to exactly compute the logarithm of a sum when you can't compute the sum directly, but if you can find a pretty tight upper bound on the sum -- note that two of the summands will be astronomically small compared to the third -- then you can continue with that. This whole argument uses pretty wide upper bounds (in particular the $18\log_{10}(n)$ is far larger than necessary) so a weaker upper bound would probably still function. – Mees de Vries Jul 26 '18 at 7:49
• $7^{3n}\equiv 1 \pmod 9$, $7^{3n+1}\equiv 7 \pmod 9$, $7^{3n+2}\equiv 4 \pmod 9$
• $7^{m}\equiv 1 \pmod 3$
• so $7^{7^{7^7}} \equiv 7 \pmod 9$ and is of the form $9k+7$ for some $k$
• any number less than $17$ (actually $79$) of the form $9k+7$ has a digit sum of $7$
• $7 \lt 10$
• any number less than $10^{10}+7$ (actually $8\times 10^{72}-1$) of the form $9k+7$ has a digit double sum of $7$
• $7^7 \lt 10^{10}$
• any number less than $10^{10^{10}}+7$ (actually $8 \times 10^{8\times 10^{72}-8} -1$) of the form $9k+7$ has a digit triple sum of $7$
• $7^{7^7} \lt 10^{10^{10}}$
• any number less than $10^{10^{10^{10}}}+7$ (actually $8\times 10^{8 \times 10^{8\times 10^{72}-8} -8}-1$) of the form $9k+7$ has a digit quadruple sum of $7$
• $7^{7^{7^7}} \lt 10^{10^{10^{10}}}$

So $7^{7^{7^7}}$ has a digit quadruple sum of $7$

I propose the following definition for the (recursive) sum-of-digits function

  \\ Pari/GP-Code
{sod(n) = local(s,d);
while(n>9,
s=0; while(n>0,
d=n % 10;  \\ the last digit to "d"
s=s+d;     \\ add "d" to the digit-sum "s"
n=n\10;   \\ shift n one decimal digit to the right
);    \\ s has now the number of digits of n,
n=s);  \\ because possibly s>9 we use this as new n and repeat
return(n);}


If we check now the sum-of-digits of consecutive powers of $7$ we get

vector(12,r,sod(7^(r-1 )))
%969 = [1, 7, 4, 1, 7, 4, 1, 7, 4, 1, 7, 4]


and we see, that this is simply periodic with period $3$

vector(12,r,sod(7^((r-1) % 3)))
%970 = [1, 7, 4, 1, 7, 4, 1, 7, 4, 1, 7, 4]


After that we need the residue of the exponent $\;^37 \pmod 3$ which- since $7 \equiv 1 \pmod 3$ is $1$.

So we have $$\text{sod}(\;^47 ) = \text{sod}(7^{\;^37 \pmod 3} ) =\text{sod}(7^{1}) = 7$$

update
To see, whether exactly 4-times iterated sum-of digits would arrive at a one-digit number I've estimated this using Pari/GP:
Here nd_xxx means "number-of-digits of xxx" , sd_xxx sum of digits of xxx. The sum is simply estimated by the average of the possible digits meaning sd_XXX = 4.5 * nd_XXX. Z is here $\;^47$.

nd_Z=%59 \\= 7^7^7^*log(7)/log(10)
%85 = 3.17741949328 E695974   \\ number digits of Z

A=sd_Z=4.5*nd_Z
%86 = 1.42983877198 E695975   \\ estimated sum of digits of Z

nd_A=log(A)/log(10)            \\ number of digits of A
%87 = 695975.155287

B=sd_A=4.5*nd_A                \\ est. sum of digits of A
%88 = 3131888.19879

nd_B=log(B)/log(10)            \\ est. number of digits of B
%89 = 6.49580625035

C=sd_B=4.5*nd_B                \\ est. sum of digits of B
%90 = 29.2311281266

nd_C=log(C)/log(10)            \\ est. number of digits of C
%91 = 1.46584557655

D=sd_C=4.5*nd_C                \\ est. sum of digits of C
%92 = 6.59630509448


So using the sum-of-digits recursively 4 times might arrive at a single digit number.

However, this answer might have missed the exact point of the question. I consider to delete it later.

• Here you don't actually know how many times you repeat the process of doing the sod, and in the original problem, we must do it a precise number of times – Andrew V Jul 25 '18 at 11:35
• @Andrej - ok, might be I've missed the focus of the question. I'll come back to this later, perhaps I'll delete my answer. – Gottfried Helms Jul 25 '18 at 11:59

$$\begin{split} 7^{7^{7^7}}= 7^{7^{823543}} &= 7^\text{a number with around >100000 but less than 1000000 digits}\\ &= \text{a number with around a number with 5 digits} \end{split}$$ Therefore, $$C$$ has $$5$$ digits