Numbers less than N that are perfect cubes and the sum of their digits reduced to a single digit is 1 | 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
function isDigitSumOne ( nm ) { if ( nm % 9 == 1 ) return true ; else return false ; } function printValidNums ( n ) { let cbrt_n = Math . ceil ( Math . pow ( n , 1 / 3 ) ) ; for ( let i = 1 ; i <= cbrt_n ; i ++ ) { let cube = Math . pow ( i , 3 ) ; if ( cube >= 1 && cube <= n && isDigitSumOne ( cube ) ) document . write ( cube + " " ) ; } } let n = 1000 ; printValidNums ( n ) ;