# WARNING: The text below provides a guidance for a Project Euler problem.

• If you pride yourself in tackling problems entirely on your own, you are encouraged to exit this post right now.

• If you are simply looking for a hint for the problem, please visit the »Project Euler’s official forum«. You may find some hints here, but if you don’t want your problem spoiled, scroll cautiously.

• If you are looking for a readily available copy/paste answer, you will not find it here. All of the code snippets in the post have been stripped of some crucial lines (these are clearly marked). It is my aim that anyone able to replicate the answer based on such snippets will have to understand the solution conceptually. At that point, by virtue of learning something new, I believe he deserves it anyway.

• Guidance for future problems will not be published before 100 people have solved the problem and there are at least two more recent problems.



### Creative numbers

The problem asks us to sum up so-called creative numbers. Number $n$ is creative if, starting from list $L = \{n\}$, any integer greater than one is reachable via sequence of steps of two types:

• Remove $a, b$ from $L$ and substitute them by $a^b$. (For example $\{2,3\} \rightarrow \{9\}$)
• Remove any integer of the form $a^b; a, b > 1$ from the list and substitute it by $a, b$. (For example $\{16\} \rightarrow \{2, 4\}$)

We need to get a better grasp on which numbers are creative. Well, for starters, any number $n$ that is not on the form $a^b; a, b > 1$ cannot be creative, as we will get stuck in the beginning. So we consider only numbers of this form. What if both $a$ and $b$ are prime? In such case the only course of action available to us is:

and we are stuck again. What if the exponent $b$ is composite? Then we find ourselves able to reach:

What if the number we are taking power of is composite? Then we can reach:

After these simple observations we arrive at the claim that is the backbone of the whole problem.

Claim. Any number $m > 1$ is reachable from $\{a, b, c\};\ a,b,c > 1$, unless $a = b = c = 2$.
Proof. In case $a = b = c = 2$, we are stuck as the only reachable lists are $\{2,2,2\}, \{2, 4\}, \{16\}$. So let from now on $c \geq 3$. We may obtain:

By the following chain of steps we can grow our number in magnitude:

Eventually, we can reach, for any $m > 2$, some number $b^{b^x}$ where $x > m + 1$. Then we simply do:

whereupon we have reached $m$. $\square$

Finally, the problem tasks us with finding $\sum_{i = 1}^{k} i \cdot \mathbb 1_{i \text{ is creative}}$ (Where $\mathbb 1_{i \text{ is creative}}$ is $1$ if $i$ is creative and $0$ otherwise.) which is by the previous discussion equal to (Any $a^b$ with at least one of $a, b$ composite can be written as $b^p$ where $b$ is composite and $p$ prime.):

A straightforward implementation seems to be fast enough with PyPy3 runtime just below one second.