6. Find all natural numbers $a$ and $b$ such that for all natural $n$, the number $(a n+1)^{6}+b$ is divisible by $n^{2}+n+1$.
Answer: $a=2, b=27$.

Solution. Note that $n^{3}-1$ is divisible by $n^{2}+n+1$. Therefore, the number $n^{3}$ gives a remainder of 1 when divided by $n^{2}+n+1$. We will consider the remainder of the division of the number $(a n+1)^{6}+b$ by $n^{2}+n+1$. For this, we will expand the brackets:

$$
(a n+1)^{6}+b=a^{6} n^{6}+6 a^{5} n^{5}+15 a^{4} n^{4}+20 a^{3} n^{3}+15 a^{2} n^{2}+6 a n+1+b
$$

The remainder will be equal to the remainder of the number

$$
\begin{aligned}
a^{6}+ & 6 a^{5} n^{2}+15 a^{4} n+20 a^{3}+15 a^{2} n^{2}+6 a n+1+b= \\
& =\left(6 a^{5}+15 a^{2}\right) n^{2}+\left(15 a^{4}+6 a\right) n+\left(a^{6}+20 a^{3}+1+b\right)= \\
& =A n^{2}+B n+C .
\end{aligned}
$$

If the number $A n^{2}+B n+C$ is divisible by the number $n^{2}+n+1$, then the number $(B-A) n+(C-A)=\left(A n^{2}+B n+C\right)-A\left(n^{2}+n+1\right)$ is also divisible by it. However, for large $n$, the number $n^{2}+n+1$ is greater than $|(B-A) n+(C-A)|$, and divisibility is only possible if $A=B=C$. The equality $A=B$ means that $6 a^{5}+15 a^{2}=15 a^{4}+6 a$, from which either $a=1$, or $5 a=2\left(a^{2}+1\right)$, i.e., $a=2$. In the first case, the equality $B=C$ is impossible, in the second case, the condition $B=C$ is equivalent to $b=27$.