Check set bits
Explanation:
operate & with 1 , it will check whether the last bit is set or not.
import java.util.*;
import java.lang.*;
import java.io.*;
class hackerranksolutionc
{
public static void main (String[] args)
{
Scanner ab=new Scanner(System.in);
int t=ab.nextInt();
while(t-->0)
{
boolean flag=false;
int n=ab.nextInt();
while(n>1)
{
if((n&1)==0)
{
flag=true;
break;
}
n=n>>1;
}
if(flag)
System.out.println("NO");
else
System.out.println("YES");
}
}
}
0 Comments:
Post a Comment