Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

BRNDG - Editorials

$
0
0

PROBLEM LINK:

Practice

Contest

Author:rahul_ojha_07

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Binary numbers,Bit Manipulation

PROBLEM:

Given the total number of biscuits Bruno ate, find the number of days he was active?

QUICK EXPLANATION:

Calculate the Binar form of the given Number and count the number of 1's

EXPLANATION:

Since for each day the biscuits doubles up as the previous day with 1 biscuits on the first day, starting from i=0, the number of biscuits Bruno supposed to have on ith day is 2i

. Only the days he was active he got biscuits. So adding the power of 2 on each day he was active, gives the total number of biscuits, i.e., N. Hence, number of 1 in the binary representation of N is the number of days he was active.

Author's solution can be found here.


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>