I'm completing the 56th question on Project Euler:
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?
I wrote this code, which gives the wrong answer:
import math
value = 0
a = 1
b = 1
while a < 100:
b = 1
while b < 100:
result = int(math.pow(a,b))
x = [int(a) for a in str(result)]
if sum(x) > value:
value = sum(x)
b = b + 1
a = a + 1
print(value)
input("")
My code outputs 978
, whereas the correct answer is
972
I already know the actual approach, but I don't know why my reasoning is incorrect. The value that gives me the greatest digital sum seems to be 8899, but adding together each digit in that result will give me 978. What am I misinterpreting in the question?