Minimum number of cubes whose sum equals to given number N | C ++ implementation of the approach ; Function to return the minimum number of cubes whose sum is k ; If k is less than the 2 ^ 3 ; Initialize with the maximum number of cubes required ; Driver code
#include <iostream> NEW_LINE using namespace std ; int MinOfCubed ( int k ) { if ( k < 8 ) return k ; int res = k ; for ( int i = 1 ; i <= k ; i ++ ) { if ( ( i * i * i ) > k ) return res ; res = min ( res , MinOfCubed ( k - ( i * i * i ) ) + 1 ) ; } return res ; } int main ( ) { int num = 15 ; cout << MinOfCubed ( num ) ; return 0 ; }