Submit  All submissions  Best solutions  Back to list 
POW_OF_2  Power of 2 
Wersja polska  English version 
Your task is to print whether given number n is a power of 2 or not.
Input
The first line of the standard input contains one integer t (t<10001) which is the number of test cases.
In each of the next t lines there is an integer n (0<n<=2*10^9).
Output
Print YES if number n is a power of 2 or NO if it is not.
Example
Input: 4
1
2
3
4
Output: YES
YES
NO
YES
Added by:  Piotr Kąkol 
Date:  20100323 
Time limit:  3.631s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS OBJC SCM qobi VB.NET 
hide comments
20190716 23:06:04
//Abhinav Srivastav #include<bits/stdc++.h> using namespace std; bool isPowerOfTwo (int x) { return x && (!(x&(x1))); } int main() { int n,a; cin>>n; while(n) { cin>>a; isPowerOfTwo(a)? cout<<"Yes"<<endl: cout<<"No"<<endl; } return 0; } plz someone tell me whats wrong with my code 

20130705 16:47:09 orange
@ Piotr Kąkol i got wa when i used ceil then got ac after using floor!!! i can't find any reason for this? in gcc 4.7.2 ceil works & in gcc 4.3.2 floor works for such type of problems. 

20110727 10:48:39 Piotr KÄ…kol
For 536870912=2^29 You print NO. ;) 

20110726 10:59:37 Nebelhom
Hi, yes me again ;) Since this one is related to "Next Power of 2", I'm pretty sure I got this one, too... unless the log function in the math module is giving odd results ;) I can replicate the example output no bother, but for some reason the Judge says it's the wrong answer :( Have I missed something obvious? Thx 