Power of 2 or not
Problem to find the given number is power of 2 (2n) or not.
Example-1:
Input : a = 128 Output : Yes Explain : 27 = 128.
Example-2:
Input : a = 8 Output : Yes Explain : 23 = 8.
Example-2:
Input : a = 6 Output : No Explain : There is no power of two value for 6.
Solution
from itertools import count a = 128 for i in count(0): k = 2**i if(k==a): print("Yes") break elif(k>a): print("No") break
Output
Yes