What is the probability that the difference of squares of two positive integers up to $30$ is divisible by $3$ or $7$? If we choose any two numbers $a$ and $b$ from the integers $1$ through $30$, what is the probability of $a^2-b^2$ of being divisible by $3$ or $7$?

Note that $a^2-b^2$ is divisible by $c$ if and only if
$$a\equiv b\equiv0\pmod{c}\qquad\text{ or }\qquad a\equiv\pm b\not\equiv0\pmod{c}.$$
Taking $c=3$ we find that the sum of the probabilities of these cases is
$$\left(\frac{10}{30}\right)^2+\left(\frac{20}{30}\right)^2=\frac{500}{900}.$$
For $c=7$ there are $9$ integers congruent to $\pm1\pmod{7}$ and $9$ integers congruent to $\pm2\pmod{7}$, but only $8$ integers congruent to $\pm3\pmod{7}$, so the sum becomes
$$\left(\frac{4}{30}\right)^2+2\cdot\left(\frac{9}{30}\right)^2+\left(\frac{8}{30}\right)^2=\frac{242}{900}.$$
Similarly the probability that $a^2-b^2$ is divisible by $21$ equals
$$\left(\frac{1}{30}\right)^2+9\cdot\left(\frac{3}{30}\right)^2+\left(\frac{2}{30}\right)^2=\frac{85}{900}.$$
So the probability that $a^2-b^2$ is divisible by either $3$ or $7$ equals
$$\frac{500}{900}+\frac{242}{900}-\frac{85}{900}=\frac{662}{900}=\frac{331}{450}.$$
