def exact_log2(num):
 if (not isinstance(num, (int, long))):
  raise TypeError(('unsupported operand type: %r' % (type(num).__name__,)))
 n = long(num)
 if (n <= 0):
  raise ValueError('cannot compute logarithm of non-positive number')
 i = 0
 while (n != 0):
  if ((n & 1) and (n != 1)):
   raise ValueError('No solution could be found')
  i += 1
  n >>= 1
 i -= 1
 assert (num == (1 << i))
 return i

def exact_log2 ( num ) : if ( not isinstance ( num , ( int , long ) ) ) : raise TypeError ( ( 'unsupported operand type: %r' % ( type ( num ) . __name__ , ) ) ) n = long ( num ) if ( n <= 0 ) : raise ValueError ( 'cannot compute logarithm of non-positive number' ) i = 0 while ( n != 0 ) : if ( ( n & 1 ) and ( n != 1 ) ) : raise ValueError ( 'No solution could be found' ) i += 1 n >>= 1 i -= 1 assert ( num == ( 1 << i ) ) return i
find and return an integer i >= 0 such that num == 2**i .