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
< ? php function printCubes ( $ a , $ b ) { $ acrt = ( int ) pow ( $ a , 1 / 3 ) ; $ bcrt = ( int ) pow ( $ b , 1 / 3 ) ; for ( $ i = $ acrt ; $ i <= $ bcrt ; $ i ++ ) if ( $ i * $ i * $ i >= $ a && $ i * $ i * $ i <= $ b ) echo $ i * $ i * $ i , " ▁ " ; } $ a = 24 ; $ b = 576 ; echo " Perfect ▁ cubes ▁ in ▁ given ▁ range : STRNEWLINE " , printCubes ( $ a , $ b ) ; ? >