human
Count all prefixes of the given binary array which are divisible by x | Function to return the count of total binary prefix which are divisible by x.
Initialize with zero.
Convert all prefixes to decimal.
If number is divisible by x then increase count.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count all prefixes of the given binary array which are divisible by x and the other steps required.
 def CntDivbyX ( arr , n , x ) :
	number = 0
	count = 0
	for i in range ( n ) :
		number = number * 2 + arr [ i ]
		if ( ( number % x == 0 ) ) :
			count += 1
	return count
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 0 , 1 , 0 , 1 , 1 , 0 ]
	n = len ( arr )
	x = 2
	print ( CntDivbyX ( arr , n , x ) )