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
< ? php function isDigitSumOne ( $ nm ) { if ( $ nm % 9 == 1 ) return true ; else return false ; } function printValidNums ( $ n ) { $ cbrt_n = ceil ( pow ( $ n , 1 / 3 ) ) ; for ( $ i = 1 ; $ i <= $ cbrt_n ; $ i ++ ) { $ cube = pow ( $ i , 3 ) ; if ( $ cube >= 1 && $ cube <= $ n && isDigitSumOne ( $ cube ) ) echo $ cube , " ▁ " ; } } $ n = 1000 ; printValidNums ( $ n ) ; ? >