Project Euler Solution 63: Powerful digit counts

Project Euler Problem 63: Powerful digit counts is one where one doesn't need to program Python and can solve it with a spreadsheet.

The 5-digit number, 16807=7⁵, is also a fifth power. Similarly, the 9-digit number, 134217728=8⁹, is a ninth power.

How many n-digit positive integers exist which are also an nth power?

I've created a spreadsheet with bases as rows and exponents as rolumns. Then I filled the cells with the formula =LEN(POWER($A2;B$1)) to give me the length of the power expression. I've marked the powers which have as many digits as the exponent with green background. Then using =COUNTIF(B2:B11; "="&B1) I have counted the number of highlighted cells. The result is this:

One can see that the exponent can only be 21, after that it gets saturated and the number never has enough digits. We sum these up and have the result.

Of course we can also write this as a Python program:

def solution() -> int:
    result = 0
    for base in range(1, 10):
        for exponent in itertools.count(1):
            num_digits = len(str(base**exponent))
            if num_digits == exponent:
                result += 1
            elif num_digits < exponent:
                break
    return result

This finds the solution in 10 µs.

Actually this problem was kind of lame, given that it is number 63. At least it only has the easiest difficulty rating of 5 %.