Perfect cubes in a range | An efficient solution to print perfect cubes between a and b ; Find cube root of both a and b ; Print cubes between acrt and bcrt ; Driver Code
function printCubes ( a , b ) { let acrt = parseInt ( Math . pow ( a , 1 / 3 ) , 10 ) ; let bcrt = parseInt ( Math . pow ( b , 1 / 3 ) , 10 ) ; for ( let i = acrt ; i <= bcrt ; i ++ ) if ( i * i * i >= a && i * i * i <= b ) document . write ( ( i * i * i ) + " " ) ; } let a = 24 ; let b = 576 ; document . write ( " " + " " + " " ) ; printCubes ( a , b ) ;