Number of perfect cubes between two given numbers | An Efficient Method to count cubes between a and b C # implementation of the above approach ; Function to count cubes between two numbers ; Driver code
using System ; class GFG { static int countCubes ( int a , int b ) { return ( int ) ( Math . Floor ( Math . Cbrt ( b ) ) - Math . Ceiling ( Math . Cbrt ( a ) ) + 1 ) ; } public static void Main ( string [ ] args ) { int a = 7 , b = 28 ; Console . WriteLine ( " Count ▁ of ▁ cubes ▁ is ▁ " + countCubes ( a , b ) ) ; } }