How to solve $(x \mod 7) - (x \mod 8) = 5$? I'm trying to solve $(x \mod 7) - (x \mod 8) = 5$ but no idea where to start. Help appreciated!

Suppose $x\neq 0$ then assuming
$$x=z+7k$$
with $z\neq 0$ we obtain
$$z-z-7k\equiv 5 \pmod 8$$
$$k\equiv 5 \pmod 8$$
and if
$$x=7k$$
we obtain
$$-k-7k\equiv 5 \pmod 8$$
$$0\equiv 5 \pmod 8$$
Therefore without any limit in the residues we have infinitely many solutions in the form
$$x=z+35 \quad z\not\equiv 0 \pmod 7$$
for example for $x=36$
$$(36 \mod 7) - (36 \mod 8) =1-(-4)= 5$$
for $x=43$
$$(43 \mod 7) - (43 \mod 8) =8-3= 5$$
Otherwise if we assume the standard convention for a complete residue system the possible solutions are
$$x=36,37,38,39,40,41$$
and by inspection we find that only $x=40,41$ work.
