Every positive integer can be written as a sum of distinct powers of two. For example,
As we can see, is written as a sum of four distinct powers of two. How many positive integers less than can be written as a sum of four distinct powers of two?
Note: is NOT valid, since appears twice.
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.
The expanded summation of powers of two of a number is another way of describing how it is written in base 2. Let's use the given example, 1 0 1 1 0 = 1 1 0 0 1 0 1 2 Notice that the coefficients given in the powers of two summation form of 101 are mirrored in it's base 2 representation - the 0th, 2nd, 5th, and 6th digits are all 1, starting with the least significant digit as the 0th power and moving left.
Writing powers of two in base 2 is rather simple. In the same way that 1 0 x is a 1 followed by x zeroes in base 10, 2 x is a 1 followed by x zeroes in base 2. 2 2 2 2 must then be a one followed by 222 digits, and is 223 digits long.
Once again in the same way that 1 0 x is the lowest x+1 digit number in base 10, 2 x is the lowest x+1 digit number in base 2. Since we're considering only numbers less than 2 2 2 2 , we are therefore considering every number with 222 digits or less in base 2.
Let's imagine a series of 222 zeroes written in a row. If we can "flip" some of them to ones, we can represent every number from 0 to 2 2 2 2 − 1 in binary. We know from earlier that if we flip any 4 unique zeroes to ones, then the number will have four terms in its summation form.
The number of different ways we can choose 4 zeroes to flip from 222 is given by the binomial coefficient n C r ( 2 2 2 , 4 ) = 4 ! ( 2 2 2 − 4 ) ! 2 2 2 ! = ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 2 1 9 ) ( 2 2 0 ) ( 2 2 1 ) ( 2 2 2 ) = 9 8 4 9 1 9 6 5
To generalize, the number of integers less than 2 a that have b terms when expressed as a sum of distinct powers of two is simply n C r ( a , b ) .
Note: This perhaps isn't the most direct path of finding the solution, but I like it because it's relatively easy to understand when solved with the binary digits analogy.