human
What is a code to count of paths in given Binary Tree with odd bitwise AND for Q queries and the other steps required given the following:
Count of paths in given Binary Tree with odd bitwise AND for Q queries | Function to count number of paths in binary tree such that bitwise AND of all nodes is Odd.
vector dp to store the count of bitwise odd paths till that vertex.
Precomputing for each value.
Check for odd value.
Number of odd elements will be + 1 till the parent node.
For even case.
Since node is even Number of odd elements will be 0.
Even value node will not contribute in answer hence dp [ i ] = previous answer.
Printing the answer for each query.
Vector to store queries"
Solution in Python:
assistant
#Here is code to count of paths in given Binary Tree with odd bitwise AND for Q queries and the other steps required.
 def compute ( query ) :
	v = [ None ] * 100001
	dp = [ None ] * 100001
	v [ 1 ] = 1
	v [ 2 ] = 0
	dp [ 1 ] = 0
	dp [ 2 ] = 0
	for i in range ( 3 , 100001 ) :
		if ( i % 2 != 0 ) :
			if ( ( i // 2 ) % 2 == 0 ) :
				v [ i ] = 1
				dp [ i ] = dp [ i - 1 ]
			else :
				v [ i ] = v [ i // 2 ] + 1
				dp [ i ] = dp [ i - 1 ] + v [ i ] - 1
		else :
			v [ i ] = 0
			dp [ i ] = dp [ i - 1 ]
	for x in query :
		print ( dp [ x ] )
query = [ 5 , 2 ]
compute ( query )