I have inequality $$(x - 1)^2 + (y - 2)^2 + (z - 3)^2 \leqslant 81$$ and want to count all number of integer solutions. I tried $$(x - 1)^2 \leqslant 81 \Leftrightarrow -8\leqslant x\leqslant 10,$$ $$(y - 2)^2 \leqslant 81 \Leftrightarrow -7\leqslant y\leqslant 11,$$ $$(z - 3)^2 \leqslant 81 \Leftrightarrow -6\leqslant y\leqslant 12.$$ Therefore, there are $19 \cdot 19 \cdot 19 = 6859 $. This result is not correct. The correct answer is 3071.
I found 102 triples $(a,b,c)$ so that $a^2 + b^2 + c^2 = 81 $ are: $(-9, 0, 0)$, $(-8, -4, -1)$, $(-8, -4, 1)$, $(-8, -1, -4)$, $(-8, -1, 4)$, $(-8, 1, -4)$, $(-8, 1, 4)$, $(-8, 4, -1)$, $(-8, 4, 1)$, $(-7, -4, -4)$, $(-7, -4, 4)$, $(-7, 4, -4)$, $(-7, 4, 4)$, $(-6, -6, -3)$, $(-6, -6, 3)$, $(-6, -3, -6)$, $(-6, -3, 6)$, $(-6, 3, -6)$, $(-6, 3, 6)$, $(-6, 6, -3)$, $(-6, 6, 3)$, $(-4, -8, -1)$, $(-4, -8, 1)$, $(-4, -7, -4)$, $(-4, -7, 4)$, $(-4, -4, -7)$, $(-4, -4, 7)$, $(-4, -1, -8)$, $(-4, -1, 8)$, $(-4, 1, -8)$, $(-4, 1, 8)$, $(-4, 4, -7)$, $(-4, 4, 7)$, $(-4, 7, -4)$, $(-4, 7, 4)$, $(-4, 8, -1)$, $(-4, 8, 1)$, $(-3, -6, -6)$, $(-3, -6, 6)$, $(-3, 6, -6)$, $(-3, 6, 6)$, $(-1, -8, -4)$, $(-1, -8, 4)$, $(-1, -4, -8)$, $(-1, -4, 8)$, $(-1, 4, -8)$, $(-1, 4, 8)$, $(-1, 8, -4)$, $(-1, 8, 4)$, $(0, -9, 0)$, $(0, 0, -9)$, $(0, 0, 9)$, $(0, 9, 0)$, $(1, -8, -4)$, $(1, -8, 4)$, $(1, -4, -8)$, $(1, -4, 8)$, $(1, 4, -8)$, $(1, 4, 8)$, $(1, 8, -4)$, $(1, 8, 4)$, $(3, -6, -6)$, $(3, -6, 6)$, $(3, 6, -6)$, $(3, 6, 6)$, $(4, -8, -1)$, $(4, -8, 1)$, $(4, -7, -4)$, $(4, -7, 4)$, $(4, -4, -7)$, $(4, -4, 7)$, $(4, -1, -8)$, $(4, -1, 8)$, $(4, 1, -8)$, $(4, 1, 8)$, $(4, 4, -7)$, $(4, 4, 7)$, $(4, 7, -4)$, $(4, 7, 4)$, $(4,8, -1)$, $(4, 8, 1)$, $(6, -6, -3)$, $(6, -6, 3)$, $(6, -3, -6)$, $(6, -3, 6)$, $(6, 3, -6)$, $(6, 3, 6)$, $(6, 6, -3)$, $(6, 6, 3)$, $(7, -4, -4)$, $(7, -4, 4)$, $(7, 4, -4)$, $(7, 4, 4)$, $(8, -4, -1)$, $(8, -4, 1)$, $(8, -1, -4)$, $(8, -1, 4)$, $(8, 1, -4)$, $(8, 1, 4)$, $(8, 4, -1)$, $(8, 4, 1)$, $(9, 0, 0)$.
How to count number of integer solutions of that inequality?
You over-count because e.g. $x=10$, $y=11$, $z=12$ makes the left hand side $243$.
First, note that all $u,v,w$ with $|u|,|v|,|w|\le 5$ lead to $u^2+v^2+w^2\le 75\le 81$. This gives us $11^3=1331$ solutions so far.
In summary, $$ 1331+6+342+606+84+216+486=3071$$