Binary numbers,Bit Manipulation
Given the total number of biscuits Bruno ate, find the number of days he was active?
Calculate the Binar form of the given Number and count the number of 1’s
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.