human
What is a code to modulo of a large Binary String and the other steps required given the following:
Modulo of a large Binary String | Function to return the value of ( str % k ).
pwrTwo [ i ] will store ( ( 2 ^ i ) % k ).
To store the result.
If current bit is 1.
Add the current power of 2.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to modulo of a large Binary String and the other steps required.
 def getMod ( _str , n , k ) :
	pwrTwo = [ 0 ] * n
	pwrTwo [ 0 ] = 1 % k
	for i in range ( 1 , n ) :
		pwrTwo [ i ] = pwrTwo [ i - 1 ] * ( 2 % k )
		pwrTwo [ i ] %= k
	res = 0
	i = 0
	j = n - 1
	while ( i < n ) :
		if ( _str [ j ] == '1' ) :
			res += ( pwrTwo [ i ] )
			res %= k
		i += 1
		j -= 1
	return res
_str = "1101"
n = len ( _str )
k = 45
print ( getMod ( _str , n , k ) )