Number of trees whose sum of degrees of all the vertices is L | C ++ implementation of the approach ; Iterative Function to calculate ( x ^ y ) in O ( log y ) ; Initialize result ; If y is odd , multiply x with result ; y must be even now y = y / 2 ; Function to return the count of required trees ; number of nodes ; Return the result ; Driver code
#include <iostream> NEW_LINE using namespace std ; #define ll  long long int NEW_LINE ll power ( int x , ll y ) { ll res = 1 ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) ; y = y >> 1 ; x = ( x * x ) ; } return res ; } ll solve ( int L ) { int n = L / 2 + 1 ; ll ans = power ( n , n - 2 ) ; return ans ; } int main ( ) { int L = 6 ; cout << solve ( L ) ; return 0 ; }