Problem 4. a) Determine the 4-digit numbers written in base 10 whose writing in base 2 contains only the digit 1.

b) Find how many 4-digit numbers written in base 10 are written in base 2 using exactly one digit 0.
Solution. a) Writing in base 10 a number written with $n$ digits of 1 in base 2, we have: $\overline{11 \ldots 1}_{(2)}=2^{n-1}+2^{n-2}+\ldots+2^{2}+2+1=2^{n}-1$ $1 p$

Numbers of four digits of the form $2^{n}-1$ are $2^{10}-1=1023,2^{11}-1=2047,2^{12}-1=$

![](https://cdn.mathpix.com/cropped/2024_06_07_3dd00a25927e70aa5fc0g-2.jpg?height=62&width=1589&top_left_y=1666&top_left_x=230)

b) Numbers that can be written in base 2 using only one digit 0 can be expressed as the difference between two numbers, where the minuend $D$ is written in base 2 only with the digit 1, and the subtrahend $S$ is written in base 2 using only one digit 1, followed by some zeros:

![](https://cdn.mathpix.com/cropped/2024_06_07_3dd00a25927e70aa5fc0g-2.jpg?height=108&width=612&top_left_y=1949&top_left_x=716)

$1 p$

Converting to base 10, the minuend $D$ is a number of the form $2^{n}-1$, and the subtrahend $S$ is of the form $2^{p}$, where $0 \leq p \leq n-2$, since for $p=n-1$ the difference is equal to $2^{n-1}-1$, which is written only with 1s. Therefore, the difference $D-S$ is between $2^{n}-1-2^{n-2}$ and $2^{n}-2$, and since $D-S$ is a four-digit number, we get $2^{n}-2 \geq$ 1000 and $2^{n}-1-2^{n-2} \leq 9999$, from which $10 \leq n \leq 13$

$1 p$

If the minuend $D$ is $2^{10}-1=1023$, for the difference to have four digits, the subtrahend $S$ can only take the values $1,2,4,8$ or 16 (5 possibilities). If $D=2^{11}-1$, then the subtrahend $S$ can be $1,2,2^{2}, \ldots, 2^{9}$ (10 possibilities), for $D=2^{12}-1$ there are 11 ways to choose $S$, and for $D=2^{13}-1$, the subtrahend can be chosen in 12 ways.

Thus, there are $5+10+11+12=38$ four-digit numbers that can be written in base 2 with only one digit 0

$3 p$