Minimum count of Full Binary Trees such that the count of leaves is N | C ++ implementation of the approach ; Function to return the minimum count of trees required ; To store the count of set bits in n ; Driver code
#include <iostream> NEW_LINE using namespace std ; int minTrees ( int n ) { int count = 0 ; while ( n ) { n &= ( n - 1 ) ; count ++ ; } return count ; } int main ( ) { int n = 7 ; cout << minTrees ( n ) ; return 0 ; }