Quadratics — Factoring, Formula, and Completing the Square
Pillar: FIX — "Fix the form of the equation to reveal its roots."
Why Quadratics Show Up Everywhere
Quadratic equations appear in competitive programming far more often than you might expect. Counting lattice points inside a circle involves \(x^2 + y^2 \leq R^2\). Optimizing a quantity often leads to maximizing or minimizing \(ax^2 + bx + c\). Recurrences like Fibonacci have a characteristic equation that is quadratic. Even binary search problems sometimes require you to solve a quadratic to determine a bound.
The goal of this lesson is fluency: given any quadratic, you should be able to find its roots quickly using whichever method is fastest for that particular equation.
Multiplying Binomials — FOIL
Before we can factor quadratics, we need to go the other direction: expanding products of binomials.
The mnemonic FOIL stands for First, Outer, Inner, Last:
Special Products
Three patterns appear so often that you should memorize them:
| Pattern | Expansion |
|---|---|
| \((a + b)^2\) | \(a^2 + 2ab + b^2\) |
| \((a - b)^2\) | \(a^2 - 2ab + b^2\) |
| \((a + b)(a - b)\) | \(a^2 - b^2\) |
The third one — difference of squares — is particularly important. It says that whenever you see \(a^2 - b^2\), you can factor it as \((a+b)(a-b)\). This identity is used constantly in number theory and competition math.
Example: \(49 - 25 = 7^2 - 5^2 = (7+5)(7-5) = 12 \times 2 = 24\).
Example: Factor \(x^2 - 16 = (x+4)(x-4)\).
Factoring Monic Quadratics
A monic quadratic has leading coefficient 1: \(x^2 + bx + c\).
From the FOIL formula, we know:
So factoring reduces to: find two numbers that add to \(b\) and multiply to \(c\).
Example: Factor \(x^2 + 7x + 12\).
We need two numbers that add to 7 and multiply to 12. Try: \(3 + 4 = 7\) and \(3 \times 4 = 12\). Done.
Example: Factor \(x^2 - 5x + 6\).
Need: add to \(-5\), multiply to \(6\). Answer: \(-2\) and \(-3\).
Example: Factor \(x^2 + 2x - 15\).
Need: add to \(2\), multiply to \(-15\). Answer: \(5\) and \(-3\).
When It Doesn't Factor Nicely
Not every quadratic factors over the integers. \(x^2 + x + 1\) requires two numbers that add to 1 and multiply to 1 — no pair of integers works. For these, you need the quadratic formula (below).
Factoring General Quadratics (\(ax^2 + bx + c\))
When \(a \neq 1\), factoring is trickier. The AC method works:
- Compute \(a \cdot c\).
- Find two numbers \(p, q\) such that \(p + q = b\) and \(p \cdot q = ac\).
- Rewrite \(bx\) as \(px + qx\) and factor by grouping.
Example: Factor \(6x^2 + 11x + 3\).
\(ac = 6 \times 3 = 18\). Need two numbers that add to 11 and multiply to 18: \(9\) and \(2\).
Check: \((3x+1)(2x+3) = 6x^2 + 9x + 2x + 3 = 6x^2 + 11x + 3\). Correct.
Solving Quadratic Equations by Factoring
Once you factor a quadratic, use the zero product property: if \(AB = 0\), then \(A = 0\) or \(B = 0\).
Example: Solve \(x^2 - 5x + 6 = 0\).
So \(x = 2\) or \(x = 3\).
Example: Solve \(2x^2 + 5x - 3 = 0\).
\(ac = -6\). Need: add to 5, multiply to \(-6\): use \(6\) and \(-1\).
So \(x = 1/2\) or \(x = -3\).
The Quadratic Formula
For any quadratic \(ax^2 + bx + c = 0\) with \(a \neq 0\):
This always works — even when factoring doesn't. Memorize it.
The Discriminant
The expression under the square root, \(\Delta = b^2 - 4ac\), is called the discriminant. It tells you the nature of the roots before you compute them:
| Discriminant \(\Delta\) | Nature of roots |
|---|---|
| \(\Delta > 0\) | Two distinct real roots |
| \(\Delta = 0\) | One repeated real root |
| \(\Delta < 0\) | No real roots (two complex roots) |
CP application: Many problems ask "does an integer solution exist?" Computing the discriminant and checking if it is a perfect square is often the fastest approach.
Example: Solve \(2x^2 - 7x + 3 = 0\).
Example: Solve \(x^2 + 4x + 5 = 0\).
No real solutions. (In the complex numbers, \(x = -2 \pm i\), but for most CP purposes we stop here.)
Completing the Square
Completing the square rewrites \(ax^2 + bx + c\) in the form \(a(x - h)^2 + k\). This reveals the vertex of the parabola and is how the quadratic formula is derived.
The Method
Start with \(x^2 + bx + c\).
- Take half the coefficient of \(x\): \(\frac{b}{2}\).
- Square it: \(\left(\frac{b}{2}\right)^2\).
- Add and subtract this value:
Example: Complete the square for \(x^2 + 6x + 2\).
Half of 6 is 3. Square: 9.
This tells us the minimum value of \(x^2 + 6x + 2\) is \(-7\), achieved when \(x = -3\).
Why This Matters
Completing the square reveals that every quadratic \(ax^2 + bx + c\) has a vertex at:
If \(a > 0\), this is the minimum. If \(a < 0\), this is the maximum. Competition problems that ask "maximize \(f(x)\)" where \(f\) is quadratic are solved immediately by finding the vertex.
CP Example: Maximize \(n(100 - n)\) for integer \(n\).
This is \(-n^2 + 100n\), a downward parabola. Vertex at \(n = -\frac{100}{2(-1)} = 50\). Maximum value: \(50 \times 50 = 2500\).
Vieta's Formulas (Degree 2)
If \(r_1\) and \(r_2\) are the roots of \(ax^2 + bx + c = 0\), then:
These relate the roots to the coefficients without computing the roots themselves. This is extremely useful when a problem asks about the sum or product of roots.
Example: Without solving, find the sum and product of the roots of \(3x^2 - 12x + 7 = 0\).
Example: Find a quadratic with roots \(5\) and \(-2\).
Sum \(= 3\), product \(= -10\). The quadratic is \(x^2 - 3x - 10 = 0\) (using \(x^2 - (\text{sum})x + (\text{product}) = 0\)).
Using Vieta's to Find Expressions of Roots
Many competition problems ask for \(r_1^2 + r_2^2\) or \(\frac{1}{r_1} + \frac{1}{r_2}\) without wanting you to find \(r_1\) and \(r_2\) individually. Vieta's lets you compute these:
Example: If \(r_1, r_2\) are roots of \(x^2 - 5x + 3 = 0\), find \(r_1^2 + r_2^2\).
Which Method Should I Use?
| Situation | Best method | Why |
|---|---|---|
| Coefficients are small, factors obvious | Factoring | Fastest when it works |
| \(a = 1\) and \(c\) is small | Factor by finding \(p + q = b\), \(pq = c\) | Quick mental math |
| Need exact roots, messy coefficients | Quadratic formula | Always works |
| Need the minimum/maximum | Completing the square | Reveals vertex directly |
| Need sum/product of roots, not roots themselves | Vieta's formulas | Avoids computing roots entirely |
| Need to check if integer roots exist | Discriminant check | \(\Delta\) must be a perfect square, and numerator divisible by \(2a\) |
In competitions, start with factoring. If the numbers do not cooperate within a few seconds, switch to the quadratic formula.
Practice Problems
Problem 1. Factor and solve: \(x^2 - 9x + 20 = 0\).
Solution
Need two numbers: add to \(-9\), multiply to \(20\). Answer: \(-4\) and \(-5\).
\((x - 4)(x - 5) = 0\), so \(x = 4\) or \(x = 5\).
Problem 2. Use the quadratic formula to solve \(3x^2 + 2x - 5 = 0\).
Solution
\(\Delta = 4 + 60 = 64\). \(\sqrt{64} = 8\).
\(x = \frac{-2 \pm 8}{6}\)
\(x = 1\) or \(x = -\frac{10}{6} = -\frac{5}{3}\)
Problem 3. Complete the square: \(x^2 - 8x + 10\).
Solution
Half of \(-8\) is \(-4\). Square: \(16\).
\(x^2 - 8x + 10 = (x - 4)^2 - 16 + 10 = (x - 4)^2 - 6\)
Minimum value is \(-6\) at \(x = 4\).
Problem 4. The roots of \(2x^2 + kx + 18 = 0\) have a product of 9. Find \(k\) and the roots.
Solution
By Vieta's, \(r_1 r_2 = \frac{18}{2} = 9\). This is consistent with the given condition.
We need more information to find \(k\) — actually, the product being 9 is automatically true for any \(k\). But if the roots are equal: \(r_1 = r_2 = 3\), then \(r_1 + r_2 = 6 = -k/2\), so \(k = -12\).
If we want the roots to be real, we need \(\Delta \geq 0\): \(k^2 - 144 \geq 0\), so \(|k| \geq 12\).
At \(k = -12\): both roots are 3. At \(k = 12\): both roots are \(-3\).
Problem 5 (Competition Style). Find the value of \(\frac{1}{r_1^2} + \frac{1}{r_2^2}\) where \(r_1, r_2\) are the roots of \(x^2 - 7x + 11 = 0\).
Solution
By Vieta's: \(r_1 + r_2 = 7\), \(r_1 r_2 = 11\).
\(r_1^2 + r_2^2 = (r_1 + r_2)^2 - 2r_1 r_2 = 49 - 22 = 27\)
Problem 6 (Competition Style). For how many integers \(n\) does \(n^2 - 19n + 99\) equal a perfect square?
Solution
Let \(n^2 - 19n + 99 = m^2\) for some non-negative integer \(m\).
Complete the square: \((n - \frac{19}{2})^2 - \frac{361}{4} + 99 = m^2\)
\((n - \frac{19}{2})^2 - m^2 = \frac{361 - 396}{4} = -\frac{35}{4}\)
Multiply by 4: \((2n - 19)^2 - (2m)^2 = -35\)
Let \(u = 2n - 19\), \(v = 2m\). Then \(u^2 - v^2 = -35\), so \((v-u)(v+u) = 35\).
Factor pairs of 35: \((1, 35)\), \((5, 7)\), \((-1, -35)\), \((-5, -7)\).
Since \(v = 2m \geq 0\), we need \(v + u\) and \(v - u\) to have the same parity (both are even or both odd). Since \(u\) is odd (\(2n - 19\)), and \(v\) is even, \(v - u\) and \(v + u\) are both odd. And \(35 = 1 \times 35 = 5 \times 7\). Both factorizations have two odd factors. Good.
Case 1: \(v - u = 1\), \(v + u = 35\). So \(v = 18\), \(u = 17\). Then \(n = 18\), \(m = 9\). Check: \(324 - 342 + 99 = 81 = 9^2\). Correct.
Case 2: \(v - u = 5\), \(v + u = 7\). So \(v = 6\), \(u = 1\). Then \(n = 10\), \(m = 3\). Check: \(100 - 190 + 99 = 9 = 3^2\). Correct.
Case 3: \(v - u = -35\), \(v + u = -1\). So \(v = -18\), but \(v \geq 0\). Skip.
Case 4: \(v - u = -7\), \(v + u = -5\). So \(v = -6\). Skip.
Case 5: \(v - u = 7\), \(v + u = 5\). So \(v = 6\), \(u = -1\). Then \(n = 9\), \(m = 3\). Check: \(81 - 171 + 99 = 9\). Correct.
Case 6: \(v - u = 35\), \(v + u = 1\). So \(v = 18\), \(u = -17\). Then \(n = 1\), \(m = 9\). Check: \(1 - 19 + 99 = 81\). Correct.
Answer: 4 integers (\(n = 1, 9, 10, 18\)).