Loading problem...
Given an integer n, determine whether it represents an exact binary power — that is, whether n can be expressed as 2^k for some non-negative integer k.
A number is considered a binary power if it equals 2 raised to some whole number exponent. For instance, 1, 2, 4, 8, 16, 32, and so on are all binary powers because they can be written as 2⁰, 2¹, 2², 2³, 2⁴, 2⁵, respectively.
Your task is to return true if the given integer is a binary power, and false otherwise.
n = 1true1 is 2⁰, which equals 2 raised to the zeroth power. Therefore, 1 is a valid binary power.
n = 16true16 equals 2⁴ (2 × 2 × 2 × 2 = 16). Since 16 can be expressed as an exact power of 2, it is a binary power.
n = 3false3 cannot be expressed as 2^k for any non-negative integer k. The powers of 2 near 3 are 2¹ = 2 and 2² = 4, so 3 is not a binary power.
Constraints