×

POW2 -Editorial

Practice

Contest

Author: bharathg

Tester: manjunath1996

Editorialist: bharathg

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.

6★bharathg
11
accept rate: 0%

 0 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 answered 27 Aug '17, 08:39 2★kunnu120 518●9 accept rate: 5%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,820
×14

question asked: 27 Aug '17, 08:06

question was seen: 234 times

last updated: 27 Aug '17, 08:39