# Solve the congruence by using the method of completing the square

Actually, I found a open problem which is the same as my problem, see Solve quadratic congruence equation by completing square. But I can not understand the answers...they are too brief...

My typical method to solve a prime power $$p^r$$ modulus congruence is first solve the corresponding $$p$$ modulus congruence and then rise the solution in some way. For example, to solve the congruence $$x^2 +x+7=0$$ (mod $$27)$$, I will first solve the congruence $$x^2 +x+7=0$$ (mod $$3)$$ and the only solution is $$1$$. Then, with the same trick used in the open problem, we can rise the solution, and finally get the solutions of the congruence modulo $$27$$.

But my textbook requires me to solve this problem with the method of completing the square. And it provides me of a hint that $$4x^2+4x+28=(2x+1)^2+27.$$ However, I have no idea about this hint. And the textbook never mentions the method of completing the square.

• So you want to solve $$4x^2+4x+28\equiv 0\pmod{27}\ \text{ or } \ x^2+x+7\equiv 0\pmod{27}$$? Commented May 10, 2019 at 23:27
• Note $2\times14+1\equiv0\pmod{27}$ Commented May 10, 2019 at 23:32
• Isn't it $2\times 14\color{red}-1\equiv 0\bmod 27$ @J.W.Tanner Commented May 10, 2019 at 23:35
• Yes, I meant 13 Commented May 10, 2019 at 23:38
• @J.W.Tanner Your argument makes more sense. I found a flaw in my reasoning. Because $u$ may not be powers of a prime, I can not argue in that way. Thanks a lot Tanner, sincerely. You helped me a lot in my study of elementary number theory. Commented May 12, 2019 at 19:57

Completing the square is simply adding some amount and subtracting it in order to get partially a square. Consider for instance $$x^2+2x=x^2+2x\underbrace{\color{green}{+1-1}}_{=+0}=(x\color{green}{+1})^2-1$$...

Your textbook suggests that $$x^2+x+7\equiv 0\bmod{27}\stackrel{\cdot 4}{\iff}4x^2+4x+28\equiv0\bmod {27}$$ $$\iff \underbrace{(2x+1)^2}_{=4x^2+4x+1}+27\equiv(2x+1)^2+0\equiv(2x+1)^2\equiv0\bmod 27\iff \ldots$$ I obtained $$x\equiv\begin{cases}4\\13\\22\end{cases}\bmod 27$$

• You mean mod $\color{red}27$ Commented May 10, 2019 at 23:53
• mod 27 for the last part perhaps
– user645636
Commented May 10, 2019 at 23:53
• $\color{red}{27}$
– user645636
Commented May 10, 2019 at 23:54
• And again, thanks for pointing the typo out! Commented May 11, 2019 at 0:12

if $$u^2 \equiv 0 \pmod {27}$$ then $$u \equiv 0 \pmod 9$$

so $$u \equiv 0,9,18 \pmod {27}$$

• Thanks Jagy. Your post helped me understand Dr. Mathva's post. But I still have problems in understanding your first step. i.e. How do we know $u\equiv 0\,($mod $9)$ provided $u^2\equiv 0\,($mod $27)\,?$ Thanks for your elaboration in advance. Commented May 11, 2019 at 3:07
• I came up a reasoning and can you help me see if it works. Since $27=3\cdot 3\cdot 3$ and $27\vert u^2 \iff (3\cdot 3\cdot 3)\vert (u\cdot u)$, we know $3\vert u$ and $(3\cdot 3)\vert u$. And so $9\vert u$. Is my reasoning correct? Thanks! Commented May 11, 2019 at 3:42