This is LaTeX code:

[latex]
$\begin{align*}(31+1)^n &= (31^n + n\cdot31^{n-1}\cdot1 + \dots + n\cdot31\cdot1^{n-1} + 1^n) \\
&= 31(31^{n-1} + n\cdot31^{n-2}\cdot1 + \dots + n\cdot31^0\cdot1^{n-1}) + 1^n \\
&= 31 \cdot nesto + 1 \equiv 1 (\mathrm{mod}\ 31)\end{align*}$
[/latex]