Let $f=aX^2+bX+c \in \mathbb{Z}[X]$ be a quadratic polynomial and $p$ a prime number. I need to find all solutions $x \in \mathbb{Z}$, s.t. $p$ divides $f(x)\in \mathbb{Z}$. I'm sure there is an algorithm for it, but unfortunately I don't know it.
-
See here. For example, $x^2+x+41$ is divisible by a prime for $x=0,1,2,3,4,5,6,7,\ldots ,39$, etc. – Dietrich Burde Oct 26 '20 at 19:34
2 Answers
Well this is equivalent to finding the roots of $ax^2 + bx + c \in \mathbb{Z}_p[x]$
$\mathbb{Z}_p$ is a field, so actually the quadratic formula still applies:
So the two solutions (assuming the descriminant is a quadratic residue) are:
$$ x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$$
So really this boils down to two problems:
- Finding the inverse of $2a$ in $\mathbb{Z}_p$ - which can be done with the extended Euclidean algorithm
- Finding the square root of a number in $\mathbb{Z}_p$, I'm not too familiar with that but https://empslocal.ex.ac.uk/people/staff/rjchapma/courses/nt13/sqrt.pdf seems like a good starting point.

- 893
- 4
- 9
Hint:
You need to study the case $p=2$ separately.
If $p \neq 2$ you have $$ax^2+bx+c= 0 \pmod{p} \Leftrightarrow \\ 4a^2x^2+4abx+4ac = 0 \pmod{p} \Leftrightarrow \\ (2ax+b)^2 = b^2-4ac \pmod{p} $$
This equation has:
- $2$ distinct solutions if $\left( \frac{b^2-4ac}{p} \right)=1$
- $1$ double solutions if $p|b^2-4ac$
- no solution if $\left( \frac{b^2-4ac}{p} \right)=-1$
Here $\left( \frac{b^2-4ac}{p} \right)$ is the Legendre symbol.
If you need to find them, you need to first figure if there are solutions and in the case, $\left( \frac{b^2-4ac}{p} \right)=1$ you have to find one solution to $$y^2=b^2-4ac$$ by trial and error.

- 132,525