You are not logged in. Please login at www.codechef.com to post your questions!

×

POW2 -Editorial

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.

asked 27 Aug '17, 08:06

bharathg's gravatar image

6★bharathg
11
accept rate: 0%

edited 27 Aug '17, 08:09


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

link

answered 27 Aug '17, 08:39

kunnu120's gravatar image

2★kunnu120
5189
accept rate: 5%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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: 233 times

last updated: 27 Aug '17, 08:39