Python in EMT – Cross Sum of Cubes

When is the cross sum (sum of the digits) of the cube of a number equal to the number?

It is obviously true for n=0 and n=1. You might be able to find n=8 with the cube 512. Then, how do you prove that there are finitely many numbers? How long will it take to find all numbers?

For a dirty estimate we have

\((9m)^3 \ge (a_0+\ldots+a_{m-1})^3 = a_0+a_1 10 + \ldots + a_{m-1} 10^{m-1} \ge 10^{m-1}\)

It is an easy exercise to show that m<7 is necessary. So we only have to check up to n=100. The cube of 100 has already 7 digits. This can be done by hand with some effort, but here is a Python program written in Euler Math Toolbox.

>function python qs (n) ...
$s=0
$while n>0:
$   s+=n%10;
$   n/=10
$return s
$endfunction
>function python test() ...
$v=[]
$for k in range(100):
$   if k == qs(k**3):
$       v.append(k)
$return v
$endfunction
>test()
 [0,  1,  8,  17,  18,  26,  27]

 

30. März 2017 von mga010
Kategorien: English, Euler | Schreibe einen Kommentar

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert