John is going to pick up 2015 peanuts on the ground in several steps according to the following rules. In the first step, he picks up 1 peanut. For each next step, he picks up either the same number of peanuts or twice the number of peanuts of the previous step. What is the minimum number of steps in which he can complete the task?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
We first observe that any number can be written as a sum of powers of two. So we start with 1+2+4+8+16+32+64+128+256+512=1023.
If we add 1024 to this we will get 2047 which exceeds 2015, so we have to squeeze in the 2015-1023=992 somewhere in between.
We write 992 by starting with the maximum power of two lower than the number given, to meet the condition of minimum number of steps that is we go on subtracting the powers of two from 992 greedily. so we go like this:
992-512=480
480-256=224
224-128=96
96-64=32
which is a power of 2 itself so we need no further decomposition.
Now we see that we need to add to our original sequence the numbers, 32, 64, 128, 256, 512 although they are already present. Here we use the fact that we can pick the same number of peanuts as the previous step.
So we have our final sequence as 1+2+4+8+16+32+32+64+64+128+128+256+256+512+512=2015.