human
Stein 's Algorithm for finding GCD | Function to implement Stein 's Algorithm.
GCD ( 0 , b ) == b.
GCD ( a , 0 ) == a , GCD ( 0 , 0 ) == 0.
Finding K , where K is the greatest power of 2 that divides both a and b ..
Dividing a by 2 until a becomes odd.
From here on , ' a ' is always odd ..
If b is even , remove all factor of 2 in b.
Now a and b are both odd . Swap if necessary so a <= b , then set b = b - a ( which is even ) ..
restore common factors of 2.
Driver code"
How can the above be solved in Python?
 What is a code to stein 's Algorithm for finding GCD and the other steps required?
assistant
#Here is code to stein 's Algorithm for finding GCD and the other steps required.
 def gcd ( a , b ) :
	if ( a == 0 ) :
		return b
	if ( b == 0 ) :
		return a
	k = 0
	while ( ( ( a b ) & 1 ) == 0 ) :
		a = a >> 1
		b = b >> 1
		k = k + 1
	while ( ( a & 1 ) == 0 ) :
		a = a >> 1
	while ( b != 0 ) :
		while ( ( b & 1 ) == 0 ) :
			b = b >> 1
		if ( a > b ) :
			temp = a
			a = b
			b = temp
		b = ( b - a )
	return ( a << k )
a = 34
b = 17
print ( " Gcd ▁ of ▁ given ▁ numbers ▁ is ▁ " , gcd ( a , b ) )