human
Space efficient iterative method to Fibonacci number | get second MSB.
consectutively set all the bits.
returns the second MSB.
Multiply function.
Function to calculate F [ ] [ ] raise to the power n.
Base case.
take 2D array to store number 's.
run loop till MSB > 0.
To return fibonacci number.
Given n"
How can the above be solved in Python?

Give me a code to space efficient iterative method to Fibonacci number and the other steps required?
assistant
#Here is code to space efficient iterative method to Fibonacci number and the other steps required.
 def getMSB ( n ) :
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return ( ( n + 1 ) >> 2 )
def multiply ( F , M ) :
	x = F [ 0 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 0 ]
	y = F [ 0 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 1 ]
	z = F [ 1 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 0 ]
	w = F [ 1 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 1 ]
	F [ 0 ] [ 0 ] = x
	F [ 0 ] [ 1 ] = y
	F [ 1 ] [ 0 ] = z
	F [ 1 ] [ 1 ] = w
def power ( F , n ) :
	if ( n == 0 or n == 1 ) :
		return
	M = [ [ 1 , 1 ] , [ 1 , 0 ] ]
	m = getMSB ( n )
	while m :
		multiply ( F , F )
		if ( n & m ) :
			multiply ( F , M )
		m = m >> 1
def fib ( n ) :
	F = [ [ 1 , 1 ] , [ 1 , 0 ] ]
	if ( n == 0 ) :
		return 0
	power ( F , n - 1 )
	return F [ 0 ] [ 0 ]
n = 6
print ( fib ( n ) )