Let $n$ be a two-digit number written in the decimal system, and let $s$ be the sum of the squares of its digits. What is the smallest and largest value of $n-s$?
We use the conventional notation for two-digit numbers: $n=10 a+b, s=a^{2}+b^{2}$, where $1 \leq a \leq 9,0 \leq b \leq 9$, and we seek the

$$
n-s=10 a+b-\left(a^{2}+b^{2}\right)=a(10-a)-b(b-1)
$$

expression's maximum and minimum values.

The maximum value of $n-s$ is clearly achieved when $a(10-a)$ is the largest and $b(b-1)$ is the smallest.

$$
a(10-a)=-a^{2}+10 a=-(a-5)^{2}+25
$$

has its maximum value at $a=5$. Meanwhile, $b(b-1)$ is the smallest when $b=0$ or $b-1=0$, i.e., $b=1$. In both cases, $n-s=25$, which is therefore the maximum value of the $n-s$ expression.

The minimum value of $n-s$ is achieved when $a(10-a)$ is the smallest and $b(b-1)$ is the largest. Since $a \neq 0$, the function takes its minimum value in the interval $(1,9)$ at $a=1$ or $a=9$. The maximum value of $b(b-1)=b^{2}-b$ in the interval $(0,9)$ is at $b=9$.

In the first case, $a=1, b=9, n-s=19-82=-63$, while in the second case, $a=9, b=9$ and $n-s=99-162=-63$, so the minimum value of $n-s$ is -63.