Is it a power of 2?
Given a positive integer
n
, your task is to find out if it’s a power of 2 or not.In case it’s a power of 2, the program should print
Yes
, and it should print No
otherwise.Input | Output |
1 | Yes |
8 | Yes |
15 | No |
Hint
You can have an auxiliary variable
powerof2 = True
and update it accordinglyConstraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB