Suppose we a number n and another value x, we have to check whether it is a power of x or not, where x is a number power of 2.
So, if the input is like n = 32768 x = 32, then the output will be True as n is x^3.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def find_pow_of_2(n): return (1 + find_pow_of_2(n / 2)) if (n > 1) else 0 def solve(n, c): cnt = 0 if n and (n & (n - 1)) == 0: while n > 1: n >>= 1 cnt += 1 return cnt % (find_pow_of_2(c)) == 0 return False n = 32768 x = 32 print(solve(n, x))