Project Euler problem 16

Source code available on GitHub.

  \(2^{15} = 32768\) and the sum of its digits is \(3 + 2 + 7 + 6 + 8 = 26\).  What is the sum of the digits of the number \(2^{1000}\)?

Easy. Define a quick digits function to return a tuple of the digits of `N`:

def digits(N):
    return tuple(int(i) for i in str(N))

Now just sum the digits of 2^{1000}. Done.

def digits(N):
    return tuple(int(i) for i in str(N))

print(sum(digits(2**1000)))

 

Leave a Reply

Your email address will not be published. Required fields are marked *