def jacobi(a, b):
 if (a == 0):
  return 0
 result = 1
 while (a > 1):
  if (a & 1):
   if ((((a - 1) * (b - 1)) >> 2) & 1):
    result = (- result)
   (a, b) = ((b % a), a)
  else:
   if ((((b * b) - 1) >> 3) & 1):
    result = (- result)
   a >>= 1
 if (a == 0):
  return 0
 return result

def jacobi ( a , b ) : if ( a == 0 ) : return 0 result = 1 while ( a > 1 ) : if ( a & 1 ) : if ( ( ( ( a - 1 ) * ( b - 1 ) ) >> 2 ) & 1 ) : result = ( - result ) ( a , b ) = ( ( b % a ) , a ) else : if ( ( ( ( b * b ) - 1 ) >> 3 ) & 1 ) : result = ( - result ) a >>= 1 if ( a == 0 ) : return 0 return result
calculates the value of the jacobi symbol where both a and b are positive integers .