TITLE: Proof for bijection of a function between positive integers and nonprime positive integers.
QUESTION [5 upvotes]: Exercise 4.39 on Concrete Mathematics mentioned a function $S(m)$:

Let $S(m)$ be the smallest positive integer $n$ for which there exists an increasing sequence of integers
  $$ m = a_1 < a_2 < \cdots < a_t = n$$
  such that $a_1a_2...a_t$ is a perfect square.
...
We have:
  $$
\begin{array}{c|cc}
m & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12\\
\hline
S(m) & 1 &6&8&4&10&12&14&15&9&18&22&20
\end{array}$$

This exercise proved that $S(i)≠S(j)$ for different $i$, $j$ and left a remark that "the sequence $S(1),\ S(2),\ S(3),\ ...$ contains every nonprime positive integer exactly once" in the appendix "Answers to Exercises" but gave no cue or reference to it. I have no idea about it's proof.

REPLY [2 votes]: Let $n$ be a composite number. Then there are sequences $a_1<a_2<\cdots <a_r = n$ such that $a_1a_2\cdots a_s$ is a square. For instance, if $n = ab$ with $a<b<n$ (which is possible since $n$ is composite), we have $a\cdot b \cdot n = n^2$.
Since there are sequences, and they all have starting points less than or equal to $n$, there is a highest starting point, say $m$. Let $m = b_1<b_2<\cdots b_s = n$ be one such sequence. 
Clearly $S(m)\leq n$, as the sequence $b_i$ shows. I claim we have equality. Assume for contradiction that $S(m) < n$. Let $m = c_1\cdot c_2\cdots c_s = S(m)$ be a sequence such that $c_1c_2\cdots c_s$ is a square. Then
$$
b_1b_2\cdots b_s\cdot c_1c_2\cdots c_t
$$
is a square. It remains a square if we take away all the terms that appear twice. $m = b_1 = c_1$ appears twice, so the smallest factor in the stripped-down product is larger than $m$. And the largest factor is still $n$, since $b_s = n$ but $c_t<n$.
What we end up with is a sequence of distinct integers which if we multiply them together we get a square, the largest of them is $n$ and the smallest is larger than $m$, contradicting the definition of $m$.
This shows that $S(m) = n$.