Numbers less than N that are perfect cubes and the sum of their digits reduced to a single digit is 1 | Java 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
class GFG { static boolean isDigitSumOne ( int nm ) { if ( nm % 9 == 1 ) return true ; else return false ; } static void printValidNums ( int n ) { int cbrt_n = ( int ) Math . cbrt ( n ) ; for ( int i = 1 ; i <= cbrt_n ; i ++ ) { int cube = ( int ) Math . pow ( i , 3 ) ; if ( cube >= 1 && cube <= n && isDigitSumOne ( cube ) ) System . out . print ( cube + " ▁ " ) ; } } public static void main ( String args [ ] ) { int n = 1000 ; printValidNums ( n ) ; } }