3
$\begingroup$

Using the quadratic formula, we have either 0, 1, or 2 solutions. I wonder if we could use it this formula for congruence? Or is there a formula to solve quadratic equation for congruence?

Edit Assume that $ax^2 + bx + c \equiv 0 \pmod{p}$, where $p$ is prime with $(a, p) = 1$, then is there a formula for this equation?

Thanks,

  • 3
    Yes: if $p\gt 2$, then you can just use the quadratic formula, suitably interpreted: "dividing" by $2a$ means multiplying by the modular inverse of $2a$ modulo $p$; and $\sqrt{b^2-4ac}$ means any modular class whose square is congruent to $b^2-4ac$ modulo $p$, if such exists. If there is no such modular class, then the quadratic is irreducible modulo $p$. If $p=2$, then you get no solutions if all of $a$, $b$, and $c$ are odd; you get a single double solution $x=1$ if $a$ and $c$ are odd, $b$ even; both $x=0,1$ if $b$ odd, $c$ even; and a single double $x=0$ solution if $b,c$ even.2011-04-04
  • 0
    @Arturo Magidin: Thank you. I got it.2011-04-04
  • 0
    Regarding the modulus $\rm\:p=2\:$ see the [Parity Root Test.](http://math.stackexchange.com/questions/26837/do-odd-imaginary-numbers-exist/26843#26843)2011-04-04

3 Answers 3

4

If $n = p$ is prime, the situation is straightforward. When $p = 2$ there are a small number of cases, and when $p > 2$ the quadratic formula holds. (Note that the quadratic formula fails when $p = 2$ because you can't divide by $2$. This is because you can't complete the square $\bmod 2$.)

If $n$ is composite, the situation is more complicated. $x$ is a solution if and only if $x$ is a solution $\bmod p^k$ for every prime power factor of $n$ by the Chinese Remainder Theorem, so in particular if, say, $n$ is a product of $k$ distinct primes there can be as many as $2^k$ solutions obtained by combining roots modulo the prime factors of $n$.

After the above step the problem reduces to the prime power case $n = p^k$. In this case the question of what solutions look like is completely answered by Hensel's lemma. Again the case $p = 2$ is special.

  • 0
    @Quiaochu Yuan: Thank you. How about if $(a, p) = 1$, is it a special case?2011-04-04
  • 1
    @Chan: if $p > 2$ and $n = p^k$ then each solution $\bmod p$ can be uniquely extended to a solution $\bmod n$ by Hensel's lemma. If $p = 2$ then I think one needs to look at solutions $\bmod 8$.2011-04-04
  • 0
    @Chan: Did you mean $(a,p)=p$? When $(a,p)=1$, you are in the "easy" case, because $a$ is invertible modulo $p$ so you can divide by $2a$.2011-04-04
  • 0
    @Quiaochu Yuan: Thank you.2011-04-04
  • 0
    @Arturo Magidin: I meant $(a, p) = 1$. I remember now, the "invertible part". Many thanks ;)2011-04-04
1

The quadratic formula works just as well modulo n as long as $(2a,n) = 1$ and $b^2-4ac$ is a quadratic residue mod n. If either of those conditions do not hold, then there are no solutions.

Edit: as pointed out in the comments, this is not a complete answer; see Qiaochu Yuan's for a much better one.

  • 1
    @Harry Stern: Thank you. That was exactly what I thought initially.2011-04-04
  • 0
    @Chan I'm glad I could be helpful!2011-04-04
  • 0
    @Harry: That's false, e.g. $\rm\ m\ n\ x^2 + x\ $ has root $\rm x = 0\ (mod\ n)\ $ and $\rm\ (2a,n) = (2\ m\ n,\ n) = n > 1\:$ for $\rm\:n>1\:.$ Also there can be arbitrarily many roots for composite $\rm\:n\:.$2011-04-04
  • 0
    @Harry Stern: It is absolutely helpful. Great thanks ;)2011-04-04
  • 0
    @Bill Dubuque you mean, if $a \equiv 0$ then we have the same problem as if $a = 0$ in the "usual" quadratic formula? Also, what do you mean by the second part?2011-04-04
  • 1
    This answer is incomplete when $n$ is composite. As Bill Dubuque says, there can be arbitrarily many roots for composite $n$ because we can combine pairs of roots modulo the prime factors of $n$ by CRT.2011-04-04
  • 0
    actually I guess it's not "the same" problem, but the quadratic equation doesn't work in that case, yes.2011-04-04
  • 0
    @Harry: If $\rm\:a\:$ is $0\:$ or a zero-divisor then the quadratic formula doesn't apply because zero-divisors aren't invertible. But the equation can still have roots in this case. For composite $\rm\:n\:$ the ring $\rm\:\mathbb Z/n\:$ is not a domain so polynomials can have more roots than their degree. So the answer is far from being as simple as the above answer misleadingly implies.2011-04-04
  • 0
    Thank you both for pointing out it was incomplete. I have edited it accordingly.2011-04-04
1

Here (link) is a thorough discussion of the steps in reducing general moduli quadratic equation problems to those of prime moduli, including the case $p=2$.