Power Digit Sum
Let S(m) denote the sum of the decimal digits of a positive integer m. Compute S(2^1000).
Problem Statement
This archive keeps the full statement, math, and original media on the page.
\(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}\)?
Problem 16: Power Digit Sum
Mathematical Development
Definition 1. For a positive integer with base-10 representation , where and , define the digit sum .
Definition 2. The digit length of a positive integer is .
Theorem 1 (Digit length of ). For all ,
Proof. By Definition 2, , where the second equality follows from the logarithmic identity .
Corollary 1. .
Theorem 2 (Digit sum congruence). For every positive integer ,
Proof. Write . Since , we have for all . Therefore .
Lemma 1 (Order of 2 modulo 9). The multiplicative order of in is .
Proof. We compute successive powers: , , , , , . Since for and , the order is exactly .
Proposition 1 (Residue of modulo 9). .
Proof. By Lemma 1, . Since , we have .
Theorem 3 (Bounds on ). For all ,
Proof. The lower bound holds because , so at least one digit is nonzero and . The upper bound follows from for each of the digits.
Corollary 2. .
Verification. The computed answer satisfies , hence , consistent with Proposition 1 and Theorem 2.
Editorial
We compute exactly and then sum its decimal digits. The reference pseudocode uses a digit array in base 10: each multiplication by propagates carries across the current digits, and the final digit array is summed. This is sufficient because repeated exact multiplication constructs the decimal expansion of without losing information.
Pseudocode
Algorithm: Digit Sum of an Exact Power
Require: Integers b ≥ 2 and n ≥ 1.
Ensure: The sum of the decimal digits of b^n.
1: Represent the current power by a decimal digit array A initialized to the value 1.
2: Repeat n times:
3: Multiply A by b and normalize carries across its decimal digits.
4: After the final multiplication, compute S ← the sum of the digits stored in A.
5: Return S.
Complexity Analysis
Proposition 2 (Time complexity). The algorithm runs in time, where .
Proof. The outer loop executes iterations. At iteration , the digit array has length . The inner loop over digits at iteration performs constant-time operations. The total work is
For , this is .
Proposition 3 (Space complexity). The algorithm uses space.
Proof. The digit array stores at most digits. No other data structure grows with .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> digits = {1};
for (int i = 0; i < 1000; i++) {
int carry = 0;
for (int j = 0; j < (int)digits.size(); j++) {
int val = digits[j] * 2 + carry;
digits[j] = val % 10;
carry = val / 10;
}
while (carry > 0) {
digits.push_back(carry % 10);
carry /= 10;
}
}
int sum = 0;
for (int d : digits) sum += d;
cout << sum << endl;
return 0;
}
"""Project Euler Problem 16: Power Digit Sum"""
def main():
print(sum(int(d) for d in str(2 ** 1000)))