Project Euler Problem 16

2^{15} = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

Project Euler Problem 16

Solution

Answer: 1366

We need the sum of the digits of $2^{1000}$.

The number is far too large to compute by hand directly, but Python supports arbitrary-precision integers, so the approach is straightforward:

  1. Compute $2^{1000}$.
  2. Convert the number to a string.
  3. Sum its decimal digits.

The power involved is:

$2^{1000}$

Python code:

n = 2**1000
digit_sum = sum(int(d) for d in str(n))
print(digit_sum)

Tracing the logic:

  • 2**1000 computes the integer exactly.
  • str(n) converts it into decimal form.
  • Each character digit is converted back to an integer and summed.

This evaluates to:

1366

Answer: 1366