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$?
 A: 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}.$$
A: As said by peter , you can simplify (a^2-b^2) =(a-b)(a+b) ..
Then you can write the sample set for determining if either (a-b) is divisible by 3 or 7 or (a+b) is divisible by 3 or 7 .. 
once you get the sample sets , you can easily calculate prob : no_of_samples/(30*30)
Though this is a hard method ,you would get your answers this way . 
A: $$(a^2 - b^2) = (a+b)(a-b)$$
Since both $3$ and $7$ are prime, at least one of $(a+b),|a-b|$ must be $3$ or $7$. Note that (Correct me if I'm wrong) you will never get both $3$ AND $7$ unless $(a,b) \in \{(2,5),(5,2)\}$.
Now It's a matter of counting the ways you can get $3$ or $7$ as a sum from the set, and as a difference from the set, excluding the special case once..
A: There are 900 combinations, which you can calculate in an Excel table and then use the MOD(number,divisor) function to get the Modulo for 3 and 7. Then you can use "COUNTIF" function to count the relevant 0-Modulo pairs.
This is of course not a Mathematical proof but can be used to verify.
