#include<stdio.h>
#include <stdlib.h>
int main()
{
long long int a;
int flag = 0;
scanf("%lld", &a);
if (a > 0)
{
while (a > 0)
{
if (a % 2 == 0 || a == 1)
{
a = a / 2;
flag = 1;
}
else
{
flag = 0;
break;
}
}
}
if (a < 0)
{
while (a <= -1)
{
if (a % 2 == 0 || a == -1)
{
a = a / 2;
flag = 1;
}
else
{
flag = 0;
break;
}
}
}
if (flag == 1)
{
printf("yes");
}
else
{
printf("no");
}
}
Given an integer N, the program must determine if it is a power of 2 or -2. If N is a power of 2 or -2, the program must print yes. Else the program must print no.
Boundary Condition(s):
-10^17 <= N <= 10^17
Input Format:
The first line contains the value of N
.
Output Format:
The first line contains either yes
or no
For the input -4503599627370496
it should print no
but it prints yes
. Solution, please