Don't know if this is a duplicate, anyway Google returns nothing relevant as usual.
I am looking for non-negative integers $n$, such that the sum of digits of $n^3$ is equal to $n$.
I have only found 7 such numbers with the property described above: $\{0, 1, 8, 17, 18, 26, 27\}$.
I have written programs to search for more such numbers, in Python and C++. Python's integers are unbounded but Python is slow. C++ is extremely fast but its integers are fixed-width, I used 64-bit unsigned integer which has the maximum range supported by CPU.
Because I take the cube of the number so I can only go up to $2^{\frac{64}{3}} \approx 2642245.95$ without overflowing.
Below is the C++ code I used to find more of such numbers, it failed to find more:
#include <iostream>
#include <cstdint>
using std::cout;
void check_cubesum() {
uint64_t cube;
int s;
for (int i = 0; i < 2642245; i++) {
cube = i * i * i;
s = 0;
while (cube) {
s += cube % 10;
cube /= 10;
}
if (i == s) {
cout << i << '\n';
}
}
}
int main()
{
check_cubesum();
}
Are there any more numbers with this property?
I have used the method described in the answer to calculate an upper bound to find numbers n with the property that sum of decimal digits of $n^p$ equals n.
def calc_limit(p):
n = 1
while True:
n1 = n + 1
if p * n1 * 9 >= 10 ** n:
n = n1
else:
break
return 10**n - 1
The calculated limit is an order of magnitude larger than the largest solution of pth power:
In [1839]: for i in range(2, 11):
...: print(i, calc_limit(i))
2 99
3 99
4 999
5 999
6 999
7 999
8 999
9 999
10 999
def power_digit_sum(p):
lim = calc_limit(p)
result = []
for i in range(lim):
s = 0
n = i**p
while n:
n, d = divmod(n, 10)
s += d
if i == s:
result.append(i)
return result
In [1840]: for i in range(2, 11):
...: print(i, power_digit_sum(i))
2 [0, 1, 9]
3 [0, 1, 8, 17, 18, 26, 27]
4 [0, 1, 7, 22, 25, 28, 36]
5 [0, 1, 28, 35, 36, 46]
6 [0, 1, 18, 45, 54, 64]
7 [0, 1, 18, 27, 31, 34, 43, 53, 58, 68]
8 [0, 1, 46, 54, 63]
9 [0, 1, 54, 71, 81]
10 [0, 1, 82, 85, 94, 97, 106, 117]
I intend to crunch dozens more powers and see what I can find. The severe overestimation of the upper-bound is a big issue. I guess I will use Pari/GP, but raising integers to big powers is memory intensive. So I need a better estimation to reduce useless computations.