Sum of Cubes

How many positive integers are there such that the number is equal to the sum of the cubes of its digits?

For example 153 153 is one of the numbers because 153 = 1 3 + 5 3 + 3 3 153=1^3+5^3+3^3


The answer is 5.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Brock Brown
Jan 2, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def valid(x):
    total = 0
    for digit in str(x):
        total += int(digit)**3
    return total == x
count = 0
for i in xrange(1, 100000):
    if valid(i):
        count += 1
print "Answer:", count

L S
Dec 16, 2014

There are 5 numbers:

1 = 1 3 1=1^3

153 = 1 3 + 5 3 + 3 3 153=1^3+5^3+3^3

370 = 3 3 + 7 3 370=3^3+7^3

371 = 3 3 + 7 3 + 1 3 371=3^3+7^3+1^3

407 = 4 3 + 7 3 407=4^3+7^3

Since the problem is tagged under CS, do you have a cs solution?

Mardokay Mosazghi - 6 years, 5 months ago

Log in to reply

Here is a python solution:

count=0
for number in range(1,10000):
    sumOfCube=0
    copy=number
    while number>0:
        sumOfCube+=(number%10)**3
        number//=10
    if sumOfCube==copy:
        count+=1
print count

There cannot be a 5-digit number that satisfy the criteria because the largest sum of cube of a 5-digit number is 5 9 3 = 3645 5*9^3=3645

The answer is 5 \boxed{5}

l s - 6 years, 5 months ago

Log in to reply

thanks @lucy s

Mardokay Mosazghi - 6 years, 5 months ago
Hasmik Garyaka
Oct 5, 2017

Python has declarative sintax:

1
2
3
4
5
6
def sum3digits(n):
     return sum((int(x))**3 for x in map(int,str(n)))

def problem527227():
    for i in range(1000000):
        if i==sum3digits(i): print(i)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...