Complete the code in python. Given a positive integer n, you can perform the following operations any number of times: n plus or minus a power of 2 to return the minimum number of operations that need to be performed to make n equal to 0. ...

First, you can use bitwise operations to calculate the result of this integer n requiring the minimum number of operands. For example, if n is 8, you only need to perform 3 operations, that is, n plus 2 to the third power, that is, 8 + 8 = 16, then subtract 2 to the third power, that is, 16 - 8 = 8, and finally subtract 2 to the power of 0, that is, 8 - 8 = 0.

Guess you like

Origin blog.csdn.net/weixin_42611310/article/details/129595095