Powerful Digit Sum
A digital sum (or digit sum) of a natural number is the sum of its decimal digits. Considering natural numbers of the form a^b, where a, b < 100, find the maximum digital sum.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
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?
Problem 56: Powerful Digit Sum
Mathematical Development
Definition 1 (Digital Sum). Let be a positive integer with decimal representation , where and . The digital sum of is
Theorem 1 (Digital Sum Congruence). For every positive integer , .
Proof. Since , it follows that for all . Therefore
Lemma 1 (Digit Count). For and , the number of decimal digits of is
Proof. A positive integer has exactly decimal digits, since iff . Applying this to and using yields the result.
Theorem 2 (Upper Bound on Digital Sum). For any positive integer with decimal digits, . Consequently, for ,
Proof. Each digit satisfies , so . The maximum digit count over is achieved at : .
Lemma 2 (Elimination of Degenerate Cases).
(i) for all .
(ii) If for some , then for all .
(iii) for all .
Proof. (i) , whose only digit is 1. (ii) is represented as a 1 followed by zeros, so . (iii) For , has at most 2 digits, so . All three bounds are far below the achievable maximum.
Proposition 1 (Heuristic on Digit Distribution). For “generic” bases (i.e., irrational), the digits of are heuristically approximately uniformly distributed over , giving an expected digit sum of approximately . Maximizing thus requires both a large digit count (large and ) and a favorable deviation toward higher digits.
Remark. This heuristic is supported by the equidistribution of the sequence modulo 1 (Weyl’s theorem) when is irrational, which governs the leading digit via Benford’s law. Full uniformity of all digits is not rigorously established but is empirically observed.
Theorem 3 (Exhaustive Search Sufficiency). The search space has pairs. For each pair, computing via big-integer arithmetic and digit extraction is feasible, and the maximum over all pairs yields the answer.
Proof. By Lemma 2, restricting to excludes only the trivially small . The pair count is bounded, and each evaluation involves a big integer of at most 198 digits.
Editorial
We exhaustively examine all pairs with and . For each fixed base , the powers are built incrementally by repeated multiplication so that is obtained from without recomputing from scratch, and the decimal digit sum of each power is evaluated. The maximum digit sum observed over the whole search is the answer.
Pseudocode
Algorithm: Maximum Digital Sum of a^b with a, b < 100
Require: The integer ranges 2 ≤ a < 100 and 1 ≤ b < 100.
Ensure: The maximum decimal digit sum among all powers a^b in the specified range.
1: Initialize best ← 0.
2: For each base a in {2, 3, ..., 99}, initialize value ← 1.
3: For each exponent b in {1, 2, ..., 99}, update value ← a · value and compute s ← the sum of the decimal digits of value.
4: If s > best, update best ← s.
5: Return best.
Complexity Analysis
Theorem 4 (Time Complexity). The algorithm runs in arithmetic operations on individual digits, where and .
Proof. The outer loops iterate over pairs (we start at 2, but include implicitly through the initialization). At each iteration, we perform one multiplication of a -digit number by a constant , which requires single-digit multiplications and carry propagations. The digit sum extraction also requires operations. Since , the total work is .
Space: for storing the current big integer (at most 198 digits).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
// Multiply a big integer (stored as digits, least significant first) by a small integer x.
vector<int> multiply(const vector<int>& num, int x) {
vector<int> result;
int carry = 0;
for (int d : num) {
int prod = d * x + carry;
result.push_back(prod % 10);
carry = prod / 10;
}
while (carry > 0) {
result.push_back(carry % 10);
carry /= 10;
}
return result;
}
int digitSum(const vector<int>& num) {
int s = 0;
for (int d : num) s += d;
return s;
}
int main() {
int maxSum = 0;
for (int a = 2; a < 100; a++) {
vector<int> power = {1}; // a^0 = 1
for (int b = 1; b < 100; b++) {
power = multiply(power, a);
int s = digitSum(power);
if (s > maxSum) {
maxSum = s;
}
}
}
cout << maxSum << endl;
return 0;
}
"""
Project Euler Problem 56: Powerful Digit Sum
Considering natural numbers of the form a^b, where a, b < 100,
find the maximum digital sum.
Answer: 972
"""
def digit_sum(n):
"""Return the sum of the decimal digits of n."""
s = 0
while n > 0:
s += n % 10
n //= 10
return s
def solve():
max_sum = 0
for a in range(2, 100):
power = 1
for b in range(1, 100):
power *= a
s = digit_sum(power)
if s > max_sum:
max_sum = s
return max_sum
if __name__ == "__main__":
answer = solve()
assert answer == 972
print(answer)