human
Check if Decimal representation of given Binary String is divisible by K or not | Function to check the binary number is divisible by K.
Array poweroftwo will store pow ( 2 , i ) % k.
Initializing the first element in Array.
Storing every pow ( 2 , i ) % k value in the array.
To store the remaining.
Iterating till N.
If current bit is 1.
Updating rem.
If completely divisible.
If not Completely divisible.
Driver Code.
Given Input.
length of string s.
Function Call"
Solution in Python:
assistant
#Here is code to check if Decimal representation of given Binary String is divisible by K or not and the other steps required.
 def divisibleByk ( s , n , k ) :
	poweroftwo = [ 0 for i in range ( n ) ]
	poweroftwo [ 0 ] = 1 % k
	for i in range ( 1 , n , 1 ) :
		poweroftwo [ i ] = ( poweroftwo [ i - 1 ] * ( 2 % k ) ) % k
	rem = 0
	for i in range ( n ) :
		if ( s [ n - i - 1 ] == '1' ) :
			rem += ( poweroftwo [ i ] )
			rem %= k
	if ( rem == 0 ) :
		return " Yes "
	else :
		return " No "
if __name__ == ' _ _ main _ _ ' :
	s = "1010001"
	k = 9
	n = len ( s )
	print ( divisibleByk ( s , n , k ) )