Cube Free Numbers smaller than n | Java Program to print all cube free numbers smaller than or equal to n . ; Returns true if n is a cube free number , else returns false . ; check for all possible divisible cubes ; Print all cube free numbers smaller than n . ; Driver program
class GFG { public static boolean isCubeFree ( int n ) { if ( n == 1 ) return false ; for ( int i = 2 ; i * i * i <= n ; i ++ ) if ( n % ( i * i * i ) == 0 ) return false ; return true ; } public static void printCubeFree ( int n ) { for ( int i = 2 ; i <= n ; i ++ ) { if ( isCubeFree ( i ) ) { System . out . print ( i + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int n = 20 ; printCubeFree ( n ) ; } }