Bitwise Power of Two
Read an integer N, then read N positive integers. For each number, print "YES" if it is a power of 2, or "NO" otherwise. You must use bitwise operators to check, no loops counting divisions.
A number x is a power of 2 if and only if x > 0 and (x & (x - 1)) == 0.
Input
- First line: an integer
N(1 <= N <= 2·10^4) - Next
Nlines: one positive integer each (1 <= x <= 2^31 - 1, the largestint)
Output
N lines, each YES or NO.
Examples
Input:
4
1
2
3
4
Output:
YES
YES
NO
YES
Input:
3
16
15
1024
Output:
YES
NO
YES
Input:
2
1073741824
1073741823
Output:
YES
NO
1073741824 is 2^30. 1073741823 is one less. In binary that's thirty
1 bits, which is as far from "exactly one bit set" as you can get.