Digit Fifth Powers
Find the sum of all numbers that can be written as the sum of fifth powers of their digits. (By convention, 1 = 1^5 is excluded since it is not a "sum.")
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: \begin {align*} 1634 &= 1^4 + 6^4 + 3^4 + 4^4\\ 8208 &= 8^4 + 2^4 + 0^4 + 8^4\\ 9474 &= 9^4 + 4^4 + 7^4 + 4^4 \end {align*}
As \(1 = 1^4\) is not a sum it is not included.
The sum of these numbers is \(1634 + 8208 + 9474 = 19316\).
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
Problem 30: Digit Fifth Powers
Mathematical Development
Definition 1. For a positive integer with decimal digits , define the digit power sum of order as . A number is a narcissistic number of order (also called a pluperfect digital invariant) if .
Theorem 1 (Finiteness of Search Space). For any fixed , the set is finite. In particular, every such satisfies , where is computable.
Proof. A -digit number satisfies . The maximum value of for a -digit number is , since each digit is at most 9. For to hold, we need . Since grows exponentially in while grows linearly, there exists a threshold beyond which , making the equation impossible. Therefore has at most digits, and .
Lemma 1 (Upper Bound for ). If , then .
Proof. We have . For a -digit number, . We need :
| Feasible | |||
|---|---|---|---|
| 6 | 354,294 | 100,000 | Yes |
| 7 | 413,343 | 1,000,000 | No |
For , , so no -digit number with can be narcissistic of order 5. Hence has at most 6 digits and .
Theorem 2 (Completeness of Exhaustive Search). The exhaustive search over finds all narcissistic numbers of order 5.
Proof. By Lemma 1, every narcissistic number of order 5 lies in . For each in this range, we compute directly and check whether . Since the search range contains all candidates, the enumeration is complete.
Theorem 3 (Enumeration of Solutions). The narcissistic numbers of order (with ) are exactly:
| Verification | |
|---|---|
| 4150 | |
| 4151 | |
| 54748 | |
| 92727 | |
| 93084 | |
| 194979 |
Proof. By exhaustive search over , these are the only satisfying .
Corollary (Answer). The sum of all narcissistic numbers of order 5 is
Editorial
We perform a bounded exhaustive search. The algorithm precomputes the fifth power of each digit, iterates through every candidate from 2 up to the proven upper bound , computes the sum of the fifth powers of its digits, and adds the number when the digit-power sum matches the original value. This is sufficient because Lemma 1 shows that no solution can lie above that bound.
Pseudocode
Algorithm: Sum of Numbers Equal to the Sum of Fifth Powers of Their Digits
Require: The decimal digit set {0, 1, ..., 9}.
Ensure: The sum of all integers that equal the sum of the fifth powers of their decimal digits.
1: Precompute w(d) ← d^5 for each digit d.
2: Initialize total ← 0.
3: For each candidate n in {2, 3, ..., 6 · 9^5}, compute s ← sum of w(d) over the decimal digits d of n.
4: If s = n, update total ← total + n.
5: Return total.
Complexity Analysis
Proposition (Time Complexity). The algorithm runs in time where .
Proof. The outer loop iterates times. For each , extracting digits and summing their fifth powers takes iterations. The fifth-power lookup is via the precomputed table. Total: . More precisely, operations.
Proposition (Space Complexity). The algorithm uses auxiliary space (the precomputed table has fixed size 10).
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() {
int pow5[10];
for (int i = 0; i < 10; i++)
pow5[i] = i * i * i * i * i;
int total = 0;
for (int n = 2; n <= 354294; n++) {
int s = 0, t = n;
while (t > 0) {
s += pow5[t % 10];
t /= 10;
}
if (s == n)
total += n;
}
cout << total << endl;
return 0;
}
def solve():
pow5 = [i**5 for i in range(10)]
total = 0
for n in range(2, 6 * 9**5 + 1):
s, t = 0, n
while t:
s += pow5[t % 10]
t //= 10
if s == n:
total += n
print(total)
if __name__ == "__main__":
solve()