':type n: int
:rtype: int'

def integerReplacement(self, n):

    result = 0
    while (n != 1):
        b = (n & 3)
        if (n == 3):
            n -= 1
        elif (b == 3):
            n += 1
        elif (b == 1):
            n -= 1
        else:
            n /= 2
        result += 1
    return result
