3. There are $n$ people standing in a row, reporting numbers in the order of $1,2, \cdots, n$ from left to right. Those whose numbers are perfect squares leave the row; the remaining people report numbers again from left to right in the order of $1,2, \cdots$, and those whose numbers are perfect squares leave the row; this continues. In this process, everyone will eventually leave the row. Let $f(n)$ denote the initial number of the last person to leave the row. Find the expression for $f(n)$ (in terms of $n$); and give the value of $f(2019)$.
3. According to the problem, we have
$$
\begin{array}{l}
f(1)=1, f(2)=2, f(3)=f(4)=3, \\
f(5)=f(6)=5, f(7)=f(8)=f(9)=7 .
\end{array}
$$

Based on this, we conjecture that for each integer $n$ in the interval $\left[m^{2}+1,(m+1)^{2}\right]$, we have
$$
f(n)=\left\{\begin{array}{ll}
m^{2}+1, & m^{2}+1 \leqslant n \leqslant m^{2}+m ; \\
m^{2}+m+1, & m^{2}+m+1 \leqslant n \leqslant(m+1)^{2} .
\end{array}\right.
$$

To prove this, we use mathematical induction on the interval $\left[m^{2}+1,(m+1)^{2}\right]$ for $m \in \mathbf{Z}_{+}$.

The conclusion (1) has already been verified for $1 \leqslant n \leqslant 3^{2}$. Assume that the conclusion holds for $n \in\left[m^{2}+1,(m+1)^{2}\right]$. We need to consider the case when $n \in\left[(m+1)^{2}+1,(m+2)^{2}\right]$.
(1) When $(m+1)^{2}+1 \leqslant n \leqslant(m+1)^{2}+(m+1)$, after the first round of counting, a total of $m+1$ people leave, and the person at the rightmost end of the remaining queue is the one who initially reported number $n$.
Let the second round of counting be $1,2, \cdots, k$. Then
$$
k=n-(m+1) \text {. }
$$

Thus, $m^{2}+m+1 \leqslant k \leqslant(m+1)^{2}$.
By the induction hypothesis, the last person to leave the queue according to the given rules is the $f(k)$-th person in the second round of counting, and $f(k)=m^{2}+m+1$.

For the person who reports this number in the second round, all $m+1$ people who left in the first round are to his left. Therefore, in the first round of counting, his number was
$$
\left(m^{2}+m+1\right)+(m+1)=(m+1)^{2}+1 \text {. }
$$

Thus, $f(n)=(m+1)^{2}+1$.
(2) When $(m+1)^{2}+(m+1)+1 \leqslant n \leqslant(m+2)^{2}$, after the first operation, the number of people remaining in the queue is denoted as $k$, and the person $A$ at the $k$-th position in the queue, in the first round of counting, was not the $(m+2)^{2}$-th person (since all people at square positions leave after reporting). Thus, after the first round of counting, $A$ had $m+1$ people leave in front of him, so in the first round of counting, $A$ was at the $k+(m+1)$-th position.
$$
\begin{array}{l}
\text { Hence }(m+1)^{2}+(m+1)+1 \leqslant k+(m+1) \\
\leqslant(m+2)^{2}-1 \\
\Rightarrow(m+1)^{2}+1 \leqslant k \leqslant(m+1)^{2}+(m+1) .
\end{array}
$$

By the induction hypothesis, for the queue $1,2, \cdots, k$, the last person to leave the queue according to the above steps is the $f(k)$-th person, and $f(k)=(m+1)^{2}+1$. Therefore, the $(m+1)^{2}+1$-th person in this case, in the first round of counting, was at the $(m+1)^{2}+(m+1)+1$-th position, i.e.,
$$
f(n)=(m+1)^{2}+(m+1)+1 \text {. }
$$

From (1) and (2), when $n \in\left[(m+1)^{2}+1,(m+2)^{2}\right]$, the conclusion also holds.
Thus, conclusion (1) is proved.
Notice that,
$$
\begin{array}{l}
m<\sqrt{m^{2}+1}<\sqrt{m^{2}+m}<m+\frac{1}{2} \\
<\sqrt{m^{2}+m+1}<m+1 .
\end{array}
$$

From the expression of conclusion (1), eliminating $m$ gives
$$
f(n)=\left\{\begin{array}{ll}
n-\sqrt{n}+1, & n \in \mathbf{Z}_{+} ; \\
{[\sqrt{n}]^{2}+1,} & 0<\sqrt{n}<\frac{1}{2} ; \\
{[\sqrt{n}]^{2}+[\sqrt{n}]+1,} & \frac{1}{2}<\sqrt{n}<1 .
\end{array}\right.
$$

In particular, since $2019 \in\left(44 \times 45+1,45^{2}\right)$, we have $f(2019)=45 \times 44+1=1981$.