TITLE: For some integer $q$, $q^2 - 5$ is divisible by all of the following EXCEPT which of the following?
QUESTION [7 upvotes]: I was stuck trying to solve a GRE math question, and this question came to my mind when I looked at the solution. The question is

For some integer $q$, $q^2 - 5$ is divisible by all of the following EXCEPT


(A) $29$ 
(B) $30$ 
(C) $31$ 
(D) $38$ 
(E) $41$ 

I solved it by eliminating answers (plugging in values for $q$ which obviously took some time and won't work for larger numbers), and the solution states:
Start small. Remember that when divided by $3, q^2$ has remainder $0$ or $1$. So $q^2 - 5$ has remainder $1$ or $2$, meaning not divisible by $3$, so B.
How do we know that the remainder when $\frac{q^2}{3}$ is only going to be $0$ or $1$ only? I know the remainder HAS to be less than 3, but how do you figure out that it can't be $2$? And how do you deduce that it can only be $1$ or $2$ when $5$ is subtracted from the result? It's easy to see when you plug in values and check, but is there a generalized method to find out?

REPLY [2 votes]: See any integer which is not a multiple of 3 can be written as
$$
q = 3K \pm 1
$$
Therefore,
$$
\ q^2 = 9\ k^2 \pm 6K + 1
$$
so, when divided by 3, it always gives remainder as 1.
While for those integers which are multiples of 3, they give remainder as 0.
Hope this Helps !!