Given an integer $n$, find all functions $f: \mathbf{Z} \rightarrow \mathbf{Z}$, such that for any integers $x, y$ we have
$$
f(x+y+f(y))=f(x)+n y \text{. }
$$
(2012, China National Training Team Test)
The original solution used Cauchy's equation. This article introduces a solution using pure algebraic manipulation.

Translate the above text into English, preserving the original text's line breaks and format, and output the translation directly.
Let $S=\{y+f(y) \mid y \in \mathbf{Z}\}$.
First, consider the case when $n=0$.
If $S=\{0\}$, then $f(x)=-x$ for all $x \in \mathbf{Z}$.
It is easy to verify that this satisfies the requirements.
If the set $S$ contains non-zero numbers, then $f$ is a periodic function. Let $d$ be the smallest positive period of $f$. Then $f$ is completely determined by the values of $f(0), f(1), \cdots, f(d-1)$, and since each number in the set $S$ must be a multiple of $d$, we have
$$
f(i) \equiv -i \pmod{d} \quad (i=0,1, \cdots, d-1).
$$

It is easy to verify that such a constructed $f$ satisfies the requirements.
In summary, when $n=0$, either $f(x)=-x$, or $f$ is a periodic function, constructed as described above.
Next, consider the case when $n \neq 0$ ($n \in \mathbf{Z}$).
Let $x=y=0$, then $f(f(0))=f(0)$.
Let $f(0)=a$, then $f(a)=a$.
Taking $y=0$ and $y=a$, we have
$$
f(x+a)=f(x), \quad f(x+2a)=f(x)+na.
$$

Combining the fact that $f$ is a periodic function, we get $a=0 \Rightarrow f(0)=0$.
Taking $x=t$ and $y=x+y+f(y)$, we have
$$
\begin{array}{l}
f(t+(x+y+f(y))+f(x+y+f(y))) \\
=f(t)+n(x+y+f(y)) \\
\Rightarrow f(t+x+y+f(x)+f(y)+ny) \\
\quad=f(t)+nx+ny+nf(y).
\end{array}
$$

Taking $t=-f(x)-ny$, we get
$$
\begin{array}{l}
f(x+y+f(y)) \\
=f(-f(x)-ny)+nx+ny+nf(y) \\
\Rightarrow f(x)+ny=f(-f(x)-ny)+nx+ny+nf(y) \\
\Rightarrow f(-f(x)-ny)=f(x)-nx-nf(y).
\end{array}
$$

Letting $x=0$, we have
$$
f(-ny)=-nf(y).
$$

Let $f(1)=m$.
Taking $y=1$, we know $f(x+m+1)=f(x)+n$.
It is easy to see that $m \neq -1$.
Letting $x=-m$, we have
$$
f(1)=f(-m)+n \Rightarrow f(-m)=m-n.
$$

It is easy to see that $m \neq 0$.
Letting $y=-m$, we have
$$
\begin{array}{l}
f(x-m+m-n)=f(x)-nm \\
\Rightarrow f(x-n)=f(x)-nm.
\end{array}
$$

For $t \in \mathbf{Z}_{+}$,
$$
\begin{array}{l}
f(nt)=f(n(t-1))+nm \\
=f(n(t-2))+2nm \\
=\cdots=f(0)+ntm=ntm;
\end{array}
$$

For $t \in \mathbf{Z}_{-}$, similarly, we get $f(nt)=ntm$.
Thus, for any $t \in \mathbf{Z}$, $f(nt)=ntm$. Combining this with equation (1), we have
$$
\begin{array}{l}
ntm=f(nt)=-nf(-t) \\
\Rightarrow f(-t)=-tm \Rightarrow f(t)'=tm.
\end{array}
$$

Substituting into the original functional equation, we get $n=m(m+1)$.
Thus, when $n \neq 0$, the conclusion is:
When $n=m(m+1)$, the solutions are
$f(x)=mx$ or $-(m+1)x$.