Numbers less than N that are perfect cubes and the sum of their digits reduced to a single digit is 1 | Python3 implementation of the approach ; Function that returns true if the eventual digit sum of number nm is 1 ; if reminder will 1 then eventual sum is 1 ; Function to print the required numbers less than n ; If it is the required perfect cube ; Driver code
import math NEW_LINE def isDigitSumOne ( nm ) : NEW_LINE INDENT if ( nm % 9 == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def printValidNums ( n ) : NEW_LINE INDENT cbrt_n = math . ceil ( n ** ( 1. / 3. ) ) NEW_LINE for i in range ( 1 , cbrt_n + 1 ) : NEW_LINE INDENT cube = i * i * i NEW_LINE if ( cube >= 1 and cube <= n and isDigitSumOne ( cube ) ) : NEW_LINE INDENT print ( cube , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT n = 1000 NEW_LINE printValidNums ( n ) NEW_LINE