Project Euler Problem 16
2^{15} = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
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:
- Compute $2^{1000}$.
- Convert the number to a string.
- 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**1000computes 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