Check if a Number is a Power of 2
Learn Bit Manipulation DSA practice problem on Onlearn.
Difficulty: easy.
Topics: How can you efficiently check if a number is a power of 2?, Mathematical Algorithms, Bitwise Operations, Loops, Basic Arithmetic, Time Complexity, Space Complexity, Optimization, bit manipulation, number properties, mathematical operations, binary representation, Powers of Two, Bitwise Operations.
Is Power of Two? Problem Statement Given a positive integer N, determine if it is a power of two. A number N is a power of two if there exists a non negative integer k such that N = 2^k. Input Specification The input consists of a single positive integer N. Output Specification Print "YES" if N is a power of two, otherwise print "NO". Constraints 1 <= N <= 2 10^9 Sample Test Cases Sample Input 1 16 Sample Output 1 YES Sample Input 2 7 Sample Output 2 NO Sample Input 3 1 Sample Output 3 YES