Maths Olympiad Prep

Library / /579 of 1394

, 2015

Combinatorics Difficulty 5.2 AIME, harder Find the answer United States

Problem:

For positive integers xx, let g(x)g(x) be the number of blocks of consecutive 1's in the binary expansion of xx. For example, g(19)=2g(19)=2 because 19=10011219=10011_{2} has a block of one 1 at the beginning and a block of two 1's at the end, and g(7)=1g(7)=1 because 7=11127=111_{2} only has a single block of three 1's. Compute g(1)+g(2)+g(3)++g(256)g(1)+g(2)+g(3)+\cdots+g(256).

A number or a short expression. Fractions can be typed as 3/2, and spacing doesn't matter.

Solutions — 2

Solution 1

Solution:

Answer: 577

We prove that g(1)+g(2)++g(2n)=1+2n2(n+1)g(1)+g(2)+\cdots+g\left(2^{n}\right)=1+2^{n-2}(n+1) for all n1n \geq 1, giving an answer of 1+269=5771+2^{6} \cdot 9=577.

First note that g(2n)=1g\left(2^{n}\right)=1, and that we can view 0,1,,2n10,1, \ldots, 2^{n}-1 as nn-digit binary sequences by appending leading zeros as necessary. (Then g(0)=0g(0)=0.)

Then for 0x2n10 \leq x \leq 2^{n}-1, xx and 2nx2^{n}-x are complementary nn-digit binary sequences (of 0's and 1's), with xx's strings of 1's (0's) corresponding to 2nx2^{n}-x's strings of 0's (resp. 1's). It follows that g(x)+g(2nx)g(x)+g\left(2^{n}-x\right) is simply 1 more than the number of digit changes in xx (or 2nx2^{n}-x), i.e. the total number of 01 and 10 occurrences in xx.

Finally, because exactly half of all nn-digit binary sequences have 0,1 or 1,0 at positions k,k+1k, k+1 (for 1kn11 \leq k \leq n-1 fixed), we conclude that the average value of g(x)+g(2nx)g(x)+g\left(2^{n}-x\right) is 1+n12=n+121+\frac{n-1}{2}=\frac{n+1}{2}, and thus that the total value of g(x)g(x) is 122nn+12=(n+1)2n2\frac{1}{2} \cdot 2^{n} \cdot \frac{n+1}{2}=(n+1) 2^{n-2}, as desired.

Solution 2

Solution:

We prove that g(1)+g(2)++g(2n1)=2n2(n+1)g(1)+g(2)+\cdots+g\left(2^{n}-1\right)=2^{n-2}(n+1).

Identify each block of 1's with its rightmost 1. Then it suffices to count the number of these "rightmost 1's." For each 1kn11 \leq k \leq n-1, the kkth digit from the left is a rightmost 1 if and only if the kk and k+1k+1 digits from the left are 1 and 0 respectively. Thus there are 2n22^{n-2} possible numbers. For the rightmost digit, it is a rightmost 1 if and only if it is a 1, so there are 2n12^{n-1} possible numbers. Sum up we have: (n1)2n2+2n1=2n2(n+1)(n-1) 2^{n-2}+2^{n-1}=2^{n-2}(n+1), as desired.

Want a route through all this instead of an archive? The track puts 2,000 problems in a working order, from AMC 10 level to the IMO shortlist.

Source: MathNet, licensed CC-BY-4.0. Statement reproduced verbatim; metadata (topic, difficulty) added by this project.