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?
Naive solution, as instructed.
import sys, os; sys.path.append(os.path.abspath('..'))
from timer import timethis
def get_digit_sum(n):
s = 0
while n:
s += n % 10
n //= 10
return s
get_digit_sum(123)
@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
solve()