|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.
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).
Print YES if number n is a power of 2 or NO if it is not.
|Added by:||Piotr Kąkol|
|Cluster:||Cube (Intel G860)|
|Languages:||All except: NODEJS OBJC SCM qobi VB.NET|
using namespace std;
bool isPowerOfTwo (int x)
return x && (!(x&(x-1)));
isPowerOfTwo(a)? cout<<"Yes"<<endl: cout<<"No"<<endl;
plz someone tell me whats wrong with my code
2013-07-05 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.
2011-07-27 10:48:39 Piotr KÄ…kol
For 536870912=2^29 You print NO. ;-)
2011-07-26 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