# Find a solution to a congruence within a specified range

My problem is to find all the integer solutions of the following conguence:

$$P=0\ \text{mod}\ 4$$

where $$p=q^2∗r^2∗y^4∗z^2∗(2∗w^4+2∗r^2∗w^4∗y^4∗z^2+r^2∗w^8∗y^4∗z^2+2) + q^2+ 2∗r^6∗w^4∗y^m∗z^6∗(w+w^2+1)∗(-w+w^2+1)∗ (-w^2+w^4+1)+ 2∗r^4∗y^8∗z^4∗(w^8+r^2∗y^4∗z^2+1)+ w∗z^2∗(2∗w^2+3∗w^3+2)+z^2+2∗a+2$$ where $$m=12$$ and all the variables are between $$0$$ and $$3$$. One way to do this is to calculate the values of $$P$$ for all the cases of its variables in the mentioned range.

If I have copied your expression correctly then

expr =
q^2 r^2 y^4 z^2 (2 w^4 + 2 r^2 w^4 y^4 z^2 + r^2 w^8 y^4 z^2 + 2) +
q^2 + 2 r^6 w^4 y^
m  z^6 (w + w^2 + 1) (-w + w^2 + 1) (-w^2 + w^4 + 1) +
2 r^4 y^8 z^4 (w^8 + r^2 y^4 z^2 + 1) +
w  z^2 (2 w^2 + 3 w^3 + 2) + z^2 + 2 a + 2;


We can find these variables

var = Union[Cases[expr, _Symbol, ∞]]
(* {a, m, q, r, w, y, z} *)


We can make an iterator

iters = {#, 1, 4} & /@ var;


and build a Boolean table

results = Table[Mod[expr, 4] == 0, ##] & @@ iters;


Apparently there are quite a lot of cases where the condition is satisfied

Tally[Flatten[results]]
(* {{True, 4352}, {False, 12032}} *)


I'll leave it to you to work out what you want to do with them!