Knowee
Questions
Features
Study Tools

Write a program in Python to test if a number is equal to the sum of the cubes of its digits. Find the smallest and largest such numbers in the range of 100 to1000

Question

Write a program in Python to test if a number is equal to the sum of the cubes of its digits. Find the smallest and largest such numbers in the range of 100 to1000

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python program that checks if a number is equal to the sum of the cubes of its digits and finds the smallest and largest such numbers in the range of 100 to 1000.

def is_cube_sum(num):
    temp = num
    sum = 0
    while temp > 0:
        digit = temp % 10
        sum += digit ** 3
        temp //= 10
    return num == sum

smallest = None
largest = None

for i in range(100, 1001):
    if is_cube_sum(i):
        if smallest is None:
            smallest = i
        largest = i

print("Smallest number: ", smallest)
print("Largest number: ", largest)

This program defines a function is_cube_sum that checks if a number is equal to the sum of the cubes of its digits. It then iterates over the numbers from 100 to 1000 (inclusive), checking each one. The smallest and largest numbers that satisfy the condition are stored and printed at the end.

This problem has been solved

Similar Questions

Find three positive numbers whose sum is 100 and whoseproduct is a maximum

Find the sum of the digits of the least natural number N, such that the sum of the cubes of the four smallest distinct divisors of N equals 2N.

Find the sum of all the integers between 100 and 1000 that are divisibleby 9.

Find the cube root of the given number. Assume that all the input test cases will be a perfect cube.Note: Do not use any inbuilt functions / libraries for your main logic.Input FormatThe first line of input contains T - the number of test cases. It is followed by T lines, each containing a single integer.Output FormatFor each test case, print the cube root of the number, separated by a new line.Constraints30 points1 <= T <= 103-109 <= N <= 10970 points1 <= T <= 106-1018 <= N <= 1018ExampleInput5-27-12510006859-19683Output-3-51019-27

think of a number that is less than 100. If you add 4 to my number you get a square number. If you subtract 5 from my number you get a cube number. Which number am I thinking of?

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.