Number of perfect cubes between two given numbers | An Efficient Method to count cubes between a and b ; Function to count cubes between two numbers ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countCubes ( int a , int b ) { return ( floor ( cbrt ( b ) ) - ceil ( cbrt ( a ) ) + 1 ) ; } int main ( ) { int a = 7 , b = 28 ; cout << " Count ▁ of ▁ cubes ▁ is ▁ " << countCubes ( a , b ) ; return 0 ; }