Let $S_{n}$ denote the sum of the digits of the number $n$ in the decimal system. Determine all numbers $n$ for which $n=S^{2}(n)-S(n)+1$
The solution to the task should start with examining how many-digit numbers can satisfy the condition. (Many people overlooked this.)

1. If $n$ is a one-digit number, then the condition can be written as: $x=x^{2}-x+1$, from which $x=1$, and this is indeed a solution to the problem.
2. If $n$ is a two-digit number, let its digits be denoted by $x$ and $y$, then $10 x+y=(x+y)^{2}-(x+y)+1$. Rearranging the equation gives $9 x=(x+y-1)^{2}$. Since the right side is a perfect square, the left side must also be a perfect square, which is true when $x=0$ (we have already examined this case), $x=1, x=4, x=9$, and in these cases $n=13, 43$, or 91.
3. If $n$ is a three-digit number, then

$$
100 x+10 y+z=(x+y+z)^{2}-(x+y+z)+1
$$

from which

$$
9(11 x+y)=(x+y+z-1)^{2}
$$

Let $11 x+y=k^{2}$, so $x+y+z=3 k+1$.

Since $x, y, z \geq 1$, $k$ is at least 4 and $x+y+z \leq 27$, so $k$ is at most 8.

Examining the cases, we find that among the three-digit numbers, there is one solution, which is 157.

There is no need to examine four-digit numbers, because $(4 \cdot 9)^{2}-4 \cdot 9+1=1261$. Thus, the first digit would be 1, but then $(1+9 \cdot 3)^{2}-(1+9 \cdot 3)+1=757$, so the number could not be a four-digit number.

Based on the work of Fata Rita (Nagykanizsa, Landler J. Gymnasium, 3rd grade)