POW2 -Editorial

easy
marathon171

#1

PROBLEM LINK:

Practice

Contest

Author: bharathg

Tester: manjunath1996

Editorialist: bharathg

DIFFICULTY:

EASY

PROBLEM:

Check if given number is power of 2 or not.

EXPLANATION:

Since the value of N is as large as 10^9,store all the powers of 2 less than 10^9 in array and check if the given number is in the array or not.

ALTERNATIVE SOLUTION:

Count the number of ones in binary representation of number N.If the count is equal to 1,answer is YES else
answer is NO.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.


#2

Nice! What I did is keep dividing the given number by 2 if at any point it gives an odd number other than 1 it’s not the power of 2, if it gives 1 then it’s the power of 2. My Solution