Loading...
Loading...
A cloud storage startup in Bengaluru only accepts block sizes that are a power of two: 1, 2, 4, 8 and so on. The upload tool sends q block sizes. A buggy client can send 0 or a negative size.
For each size, print YES if it is a power of two (2 to the power k for some k ≥ 0), otherwise print NO.
YES or NO for the i-th size.long)Example
Input
5 1 6 8 0 -4
Output
YES NO YES NO NO
1 and 8 are powers of two. 6 is not. 0 and -4 can never be powers of two.
Try the problem first. Open one hint at a time.
A power of two has exactly one 1 bit in binary.
Look at what x - 1 does to that single 1 bit and the zeros below it. What is x & (x - 1) then?
x & (x - 1) is 0 for 0 and for the smallest long too. Check that x > 0 first.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor