5. Let $n$ be a composite number. For each proper divisor $d$ of $n$ (a proper divisor of a positive integer $n$ is a divisor $d$ such that $d \mid n$ and $1 < d < n$), write the number $d+1$ on the blackboard. Find all positive integers $n$ such that the numbers written on the blackboard are exactly the proper divisors of some positive integer $m$.
5. Let the smallest proper divisor of $n$ be $p$.

It is easy to see that $p$ is a prime number.
Also, $p+1$ is the smallest proper divisor of $m$, so $p+1$ is also a prime number. Therefore, $p=2$.
Thus, 3 is the smallest proper divisor of $m$.
Hence, $m$ is an odd number (otherwise, $m$ would have a proper divisor of 2).
Therefore, all proper divisors of $m$ are odd, and all proper divisors of $n$ are even.
Thus, $n$ is a power of 2. Let $n=2^{k}\left(k \in \mathbf{Z}_{+}, k \neq 1\right)$.
Therefore, the largest proper divisor of $m$ is $2^{k-1}+1$, i.e.,
$$
m=3\left(2^{k-1}+1\right) \text {. }
$$

If $k \geqslant 4$, then $2^{k-2}$ is a proper divisor of $n$, and $2^{k-2} \geqslant 4$. Hence, $2^{k-2}+1 \geqslant 5$ is a proper divisor of $m$.
Thus, $\left(2^{k-2}+1\right) \mid\left(2^{k-1}+1\right)$.
But $\left(2^{k-2}+1,2^{k-1}+1\right)=\left(2^{k-1}+1,1\right)=1$, a contradiction.
Therefore, $k=2,3$, i.e., $n=4,8$.
Upon verification, $n=4,8$ both satisfy the conditions.
Therefore, $n=4$ or 8.