4
$\begingroup$

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.

$\endgroup$
6
  • 1
    $\begingroup$ For future such projects , download the free and easy to use PARI/GP which can handle (almost) arbitary large integers. $\endgroup$
    – Peter
    Commented Oct 9, 2023 at 17:56
  • $\begingroup$ No further solution upto $n=10^9$ , I think we can bound the possible positive integers to show that the list is complete. $\endgroup$
    – Peter
    Commented Oct 9, 2023 at 18:00
  • 11
    $\begingroup$ the sum of the digits of $n^3$ is at most (roughly) $9 \log_{10}(n^3) = 27 \log_{10} n$, which is smaller than $n$ for $n>50$ $\endgroup$ Commented Oct 9, 2023 at 18:02
  • 2
    $\begingroup$ oeis.org/A046459 $\endgroup$
    – Dan
    Commented Oct 9, 2023 at 23:34
  • $\begingroup$ And see also oeis.org/A046000 for higher powers $\endgroup$ Commented Oct 10, 2023 at 8:25

1 Answer 1

10
$\begingroup$

(Note: The question has been edited. The answer here was designed for the original question in whivh $p=3$. Questioners please don't do this, ask separate follow-up questions.)

Suppose the number $M$ (except $0$) has $n$ digits. Then it is at least $10^{n-1}$ whereas the cube can't have more than $3n$ digits each $\le9$. So a necessary condition for the equality in question is $27n\ge10^{n-1}$. This fails if $n\ge3$, so any solution set testing all numbers up to $99$ must be complete.

We can use a descent .ethod to decrease this bound of $99$. Given that $M$ has only two digits, its cube cannot have more than six and thus the dugit sum of $M^3$ cannot exceed $54$. So then $M\le54$.

In turn, with $M$ now bounded by $54$, $M^3<190000$ and then the sum of digits of $M^3$ drops to $45$. Thus $M\le45$ and, with cubes required t9 be $\in\{0,1,8\}\bmod 9$, only a few cabdidates above $27$ would need to be considered.

$\endgroup$
2
  • 1
    $\begingroup$ There is a hole in your answer, though. The limit I calculated using your method is too big. For numbers $n$ with similar properties in other powers, that is, the digit sum of $n^p$ equals $n$, for square the limit is 99 but the only nontrivial solution is 9, for powers 4 to 9, it is 999, but the only numbers with such properties with 9th power are {0, 1, 54, 71, 81}, only in 10th power there are three digit numbers: {0, 1, 82, 85, 94, 97, 106, 117}. $\endgroup$ Commented Oct 10, 2023 at 7:40
  • $\begingroup$ There is also a hole in the question which has been edited from the original. Please ask separate follow-up questions instead of changing the problem statement in a given question. $\endgroup$ Commented Oct 10, 2023 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .