Project Euler Problem #56

April 3rd, 2009
by Serinox

Problem #56 says:

A googol (10^(100)) is a massive number: one followed by one-hundred zeros;
 100^(100) 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, a^(b), where a, b < 100, what is
 the maximum digital sum?

This is a simple iterate and check problem. Solution in python because we need to deal with very big numbers.

def GetDigitSum(a):
    Sum = 0
    digits = list(str(a))
    for i in range(len(digits)):
        Sum = Sum + int(digits[i])
    return Sum

MaxDigitalSum = 0;
a=1

while (a<100):
    b=1
    while (b<100):
        if(GetDigitSum((a**b))>MaxDigitalSum):
            MaxDigitalSum = GetDigitSum((a**b))
        b = b + 1
    a = a + 1

print "Calculated the max digital sum to be:"
print MaxDigitalSum

Posted in Project Euler | Comments (0)

No comments yet

Leave a Reply

You must be logged in to post a comment.