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.
look for factors of 2 a is even.
b is odd.
both a and b are even.
a is odd , b is even.
reduce larger number.
Driver code"
Solution in Python:
assistant
#Here is code to stein 's Algorithm for finding GCD and the other steps required.
 def gcd ( a , b ) :
	if ( a == b ) :
		return a
	if ( a == 0 ) :
		return b
	if ( b == 0 ) :
		return a
	if ( ( ~ a & 1 ) == 1 ) :
		if ( ( b & 1 ) == 1 ) :
			return gcd ( a >> 1 , b )
		else :
			return ( gcd ( a >> 1 , b >> 1 ) << 1 )
	if ( ( ~ b & 1 ) == 1 ) :
		return gcd ( a , b >> 1 )
	if ( a > b ) :
		return gcd ( ( a - b ) >> 1 , b )
	return gcd ( ( b - a ) >> 1 , a )
a , b = 34 , 17
print ( " Gcd ▁ of ▁ given ▁ numbers ▁ is ▁ " , gcd ( a , b ) )