Subfield: Combinatorics


Question: A school has a row of $n$ open lockers, numbered 1 through $n$. After arriving at school one day, Josephine starts at the beginning of the row and closes every second locker until reaching the end of the row, as shown in the example below. Then on her way back, she closes every second locker that is still open. She continues in this manner along the row, until only one locker remains open. Define $f(n)$ to be the number of the last open locker. For example, if there are 15 lockers, then $f(15)=11$ as shown below:

![](https://cdn.mathpix.com/cropped/2023_12_21_7e10dbc5f8ae70c21b8eg-1.jpg?height=449&width=1283&top_left_y=1719&top_left_x=429)
Prove that there is no positive integer $n$ such that $f(n)=2005$ and there are infinitely many positive integers $n$ such that $f(n)=f(2005)$.

Solution:
First, we calculate $f(n)$ for $n$ from 1 to 32 , to get a feeling for what happens. We obtain $1,1,3,3,1,1,3,3,9,9,11,11,9,9,11,11,1,1,3,3,1,1,3,3,9,9,11,11,9,9,11,11$. This will help us to establish some patterns.

Next, we establish two recursive formulas for $f(n)$.

First, from our pattern, it looks like $f(2 m)=f(2 m-1)$.

Why is this true in general?

Consider a row of $2 m$ lockers.

On the first pass through, Josephine shuts all of the even numbered lockers, leaving open lockers $1,3, \ldots, 2 m-1$.

These are exactly the same open lockers as if she had started with $2 m-1$ lockers in total. Thus, as she starts her second pass from right to left, the process will be the same now whether she started with $2 m$ lockers or $2 m-1$ lockers.

Therefore, $f(2 m)=f(2 m-1)$.

This tells us that we need only focus on the values of $f(n)$ where $n$ is odd.

Secondly, we show that $f(2 m-1)=2 m+1-2 f(m)$.

(It is helpful to connect $n=2 m-1$ to a smaller case.)

Why is this formula true?

Starting with $2 m-1$ lockers, the lockers left open after the first pass are $1,3, \ldots, 2 m-1$, ie. $m$ lockers in total.

Suppose $f(m)=p$. As Josephine begins her second pass, which is from right to left, we can think of this as being like the first pass through a row of $m$ lockers.

Thus, the last open locker will be the $p$ th locker, counting from the right hand end, from the list $1,3, \ldots, 2 m-1$.

The first locker from the right is $2 m-1=2 m+1-2(1)$, the second is $2 m-3=2 m+1-2(2)$, and so on, so the $p$ th locker is $2 m+1-2 p$.

Therefore, the final open locker is $2 m+1-2 p$, ie. $f(2 m-1)=2 m+1-2 p=2 m+1-2 f(m)$.

Using these two formulae repeatedly,

$$
\begin{aligned}
f(4 k+1) & =f(2(2 k+1)-1) \\
& =2(2 k+1)+1-2 f(2 k+1) \\
& =4 k+3-2 f(2(k+1)-1) \\
& =4 k+3-2(2(k+1)+1-2 f(k+1)) \\
& =4 k+3-2(2 k+3-2 f(k+1)) \\
& =4 f(k+1)-3
\end{aligned}
$$



and

$$
\begin{aligned}
f(4 k+3) & =f(2(2 k+2)-1) \\
& =2(2 k+2)+1-2 f(2 k+2) \\
& =4 k+5-2 f(2 k+1) \\
& =4 k+5-2 f(2(k+1)-1) \\
& =4 k+5-2(2(k+1)+1-2 f(k+1)) \\
& =4 k+5-2(2 k+3-2 f(k+1)) \\
& =4 f(k+1)-1
\end{aligned}
$$

From our initial list of values of $f(n)$, it appears as if $f(n)$ cannot leave a remainder of 5 or 7 when divided by 8 . So we use these recursive relations once more to try to establish this:

$$
\begin{aligned}
f(8 l+1) & =4 f(2 l+1)-3 \quad(\text { since } 8 l+1=4(2 l)+1) \\
& =4(2 l+3-2 f(l+1))-3 \\
& =8 l+9-8 f(l+1) \\
& =8(l-f(l+1))+9 \\
f(8 l+3) & =4 f(2 l+1)-1 \quad(\text { since } 8 l+3=4(2 l)+3) \\
& =4(2 l+3-2 f(l+1))-1 \\
& =8 l+11-8 f(l+1) \\
& =8(l-f(l+1))+11
\end{aligned}
$$

Similarly, $f(8 l+5)=8 l+9-8 f(l+1)$ and $f(8 l+7)=8 l+11-8 f(l+1)$.

Therefore, since any odd positive integer $n$ can be written as $8 l+1,8 l+3,8 l+5$ or $8 l+7$, then for any odd positive integer $n, f(n)$ is either 9 more or 11 more than a multiple of 8 . Therefore, for any odd positive integer $n, f(n)$ cannot be 2005, since 2005 is not 9 more or 11 more than a multiple of 8 .

Thus, for every positive integer $n, f(n) \neq 2005$, since we only need to consider odd values of $n$.

Next, we show that there are infinitely many positive integers $n$ such that $f(n)=f(2005)$. We do this by looking at the pattern we initially created and conjecturing that

$$
f(2005)=f\left(2005+2^{2 a}\right)
$$

if $2^{2 a}>2005$. (We might guess this by looking at the connection between $f(1)$ and $f(3)$ with $f(5)$ and $f(7)$ and then $f(1)$ through $f(15)$ with $f(17)$ through $f(31)$. In fact, it appears to be true that $f\left(m+2^{2 a}\right)=f(m)$ if $2^{2 a}>m$.)



Using our formulae from above,

$$
\begin{aligned}
& f\left(2005+2^{2 a}\right)=4 f\left(502+2^{2 a-2}\right)-3 \quad\left(2005+2^{2 a}=4\left(501+2^{2 a-2}\right)+1\right) \\
& =4 f\left(501+2^{2 a-2}\right)-3 \\
& =4\left(4 f\left(126+2^{2 a-4}\right)-3\right)-3 \quad\left(501+2^{2 a-2}=4\left(125+2^{2 a-4}\right)+1\right) \\
& =16 f\left(126+2^{2 a-4}\right)-15 \\
& =16 f\left(125+2^{2 a-4}\right)-15 \\
& =16\left(4 f\left(32+2^{2 a-6}\right)-3\right)-15 \\
& =64 f\left(32+2^{2 a-6}\right)-63 \\
& =64 f\left(31+2^{2 a-6}\right)-63 \\
& =64\left(4 f\left(8+2^{2 a-8}\right)-1\right)-63 \\
& =256 f\left(8+2^{2 a-8}\right)-127 \\
& =256 f\left(7+2^{2 a-8}\right)-127 \\
& =256\left(4 f\left(2+2^{2 a-10}\right)-1\right)-127 \quad\left(7+2^{2 a-8}=4\left(1+2^{2 a-10}\right)+3\right) \\
& =1024 f\left(2+2^{2 a-10}\right)-383 \\
& =1024 f\left(1+2^{2 a-10}\right)-383 \\
& \left(125+2^{2 a-4}=4\left(31+2^{2 a-6}\right)+1\right) \\
& \left(31+2^{2 a-6}=4\left(7+2^{2 a-8}\right)+3\right)
\end{aligned}
$$

(Notice that we could have removed the powers of 2 from inside the functions and used this same approach to show that $f(2005)=1024 f(1)-383=641$.)

But, $f\left(2^{2 b}+1\right)=1$ for every positive integer $b$.

Why is this true? We can prove this quickly by induction.

For $b=1$, we know $f(5)=1$.

Assume that the result is true for $b=B-1$, for some positive integer $B \geq 2$.

Then $f\left(2^{2 B}+1\right)=f\left(4\left(2^{2 B-2}\right)+1\right)=4 f\left(2^{2 B-2}+1\right)-3=4(1)-3=1$ by our induction hypothesis.

Therefore, if $a \geq 6$, then $f\left(1+2^{2 a-10}\right)=f\left(1+2^{2(a-5)}\right)=1$ so

$$
f\left(2005+2^{2 a}\right)=1024(1)-383=641=f(2005)
$$

so there are infinitely many integers $n$ for which $f(n)=f(2005)$.

Final answer: 证明题，略