Powerful digit sum

A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.

Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?


Idea

Naive solution, as instructed.


In [1]:
import sys, os; sys.path.append(os.path.abspath('..'))
from timer import timethis
In [2]:
def get_digit_sum(n):
    s = 0
    while n:
        s += n % 10
        n //= 10
    return s
In [3]:
get_digit_sum(123)
Out[3]:
6
In [4]:
@timethis
def solve():
    m = 0
    for a in range(100):
        for b in range(100):
            n = pow(a, b)
            m = max(m, get_digit_sum(n))
    return m
In [5]:
solve()
Run for 0.312 seconds
Out[5]:
972