human
Number of full binary trees such that each node is product of its children | Return the number of all possible full binary tree with given product property ..
Finding the minimum and maximum values in given array ..
Marking the presence of each array element and initialising the number of possible full binary tree for each integer equal to 1 because single node will also contribute as a full binary tree ..
From minimum value to maximum value of array finding the number of all possible Full Binary Trees ..
Find if value present in the array.
For each multiple of i , less than equal to maximum value of array.
If multiple is not present in the array then continue ..
Finding the number of possible Full binary trees for multiple j by multiplying number of possible Full binary tree from the number i and number of possible Full binary tree from i / j ..
Condition for possiblity when left chid became right child and vice versa ..
Driver Code"
Solution in Python:
assistant
#Here is code to number of full binary trees such that each node is product of its children and the other steps required.
 def numoffbt ( arr , n ) :
	maxvalue = - 2147483647
	minvalue = 2147483647
	for i in range ( n ) :
		maxvalue = max ( maxvalue , arr [ i ] )
		minvalue = min ( minvalue , arr [ i ] )
	mark = [ 0 for i in range ( maxvalue + 2 ) ]
	value = [ 0 for i in range ( maxvalue + 2 ) ]
	for i in range ( n ) :
		mark [ arr [ i ] ] = 1
		value [ arr [ i ] ] = 1
	ans = 0
	for i in range ( minvalue , maxvalue + 1 ) :
		if ( mark [ i ] != 0 ) :
			j = i + i
			while ( j <= maxvalue and j // i <= i ) :
				if ( mark [ j ] == 0 ) :
					continue
				value [ j ] = value [ j ] + ( value [ i ] * value [ j // i ] )
				if ( i != j // i ) :
					value [ j ] = value [ j ] + ( value [ i ] * value [ j // i ] )
				j += i
		ans += value [ i ]
	return ans
arr = [ 2 , 3 , 4 , 6 ]
n = len ( arr )
print ( numoffbt ( arr , n ) )