# Solve quadratic congruence equation by completing square

Q: Solve the congruence $$x^2+x+7\equiv 0$$ (mod $$27$$) by using the method of completing the square from elementary algebra, thus $$4x^2+4x+28=(2x+1)^2+27$$. Solve this congruence (mod $$81$$) by the same method.

Thought: I follow its direction to get $$(2x+1)^2 \equiv 0 \quad \text{mod }27$$ But then I don't know how to continue....

On the other hand, I use the method learned in class: first to solve $$x^2+x+7\equiv 0$$ (mod $$3$$), which only $$x=1$$ is a solution. Then it is a singular root since $$f'(1)=3\equiv 0$$ mod $$3$$. And $$f(1)\equiv 0$$ mod $$9$$ implies that $$f(x)\equiv 0$$ mod(9) has 3 solutions: $$1, 4, 7$$. Further to calculate, no solution in mod $$81$$, and have3 solutions in mod $$27$$.

But as the question required, how can I use completing square method to do? Thank you.

$$(2x+1)^2\equiv0\implies(2x+1)^2\equiv0,81,324\implies2x+1\equiv0,\pm9,\pm18\implies x\equiv\cdots\pmod{27}$$
Since I don't know your background, let me recall the definition of the $$p$$-adic valuation on $$\mathbf Z$$ associated to a prime $$p$$. Any $$a\in \mathbf Z$$ can be written uniquely as $$a=a'p^n$$, with $$n$$ maximal, and we define $$v_p (a)=n$$. Obviously $$v_p (ab)=v_p (a)+v_p (b)$$. The so called ultrametric inequality is perhaps less well known : $$v_p (a+b)\ge min (v_p (a),v_p (b))$$, with equality if $$v_p (a)\neq v_p (b)$$ (check). This is elementary but useful, because it gives us a guideline in calculations.
Back to your question: the congruence $$(2x+1)^2+27\equiv 0$$ mod $$27$$ implies $$2v_3(2x+1))\ge3$$, hence $$v_3(2x+1)\ge \frac 32$$, or $$v_3(2x+1)\ge2$$. But $$2x+1=2(x-1)+3$$, so the ultrametric inequality implies $$v_3(x-1)=1$$ (NB: one can see directly from the start that $$v_3(x-1)\ge1$$, but this is less precise). Since $$\mathbf Z/27$$ surjects canonically onto $$\mathbf Z/27$$, one checks immediately that the solutions of the congruence are $$1,4,7$$ mod $$27$$.
The congruence $$(2x+1)^2+27\equiv 0$$ mod $$81$$ implies $$v_3(LHS)\ge4$$, and the ultrametric inequality requires this time that $$2v_3(2x+1)=v_3(3^3)$$, or $$v_3(2x+1)=\frac 32$$: impossible.