23.1. (SRP, 62). Under what restrictions on the integers $p$ and $q$:

a) the polynomial $P(x)=x^{2}+p x+q$ takes even (odd) values for all $x \in \mathbf{Z}$;

b) the polynomial $Q(x)=x^{3}+p x+q$ takes values divisible by 3 for all $x \in \mathbf{Z}$?
23.1. a) The values of $P(x)$ for all $x \in \mathbf{Z}$ have the same parity if and only if each of the numbers

$$
P(x+1)-P(x)=\left((x+1)^{2}+p(x+1)+q\right)-\left(x^{2}+p x+q\right)=2 x+1+p
$$

is divisible by 2, i.e., when $p$ is odd. In this case, the parity of all values of $P(x)$ is uniquely determined by the parity of the number $q=P(0)$. Thus, all values of $P(x)$ are even (odd) when $p$ is odd and $q$ is even (respectively, odd).

b) Since $Q(x)=x\left(x^{2}+p\right)+q$, the values of $Q(3 x)=3 x\left(9 x^{2}+p\right)+q$ for all $x \in \mathbf{Z}$ are divisible by 3 if and only if the number $q$ is divisible by 3. In this case, each of the values

$$
Q(3 x \pm 1)=(3 x \pm 1)\left(9 x^{2} \pm 6 x+1+p\right)+q \equiv \pm(1+p)(\bmod 3)
$$

is divisible by 3 if and only if the number $1+p$ is divisible by 3. Thus, all values of $Q(x)$ are divisible by 3 under the conditions

$$
q \equiv 0(\bmod 3), \quad p \equiv 2(\bmod 3)
$$