# When $p \mid a^2+ab+b^2$?

Let $p$ be an odd prime; and $a$ and $b$ are integers with $1\leq a, b \leq \dfrac{p-1}{2}$.

Is it true that

$p \mid a^2+ab+b^2 \text{ (for some choice of } a \text{ and } b) \iff p \not \equiv 2 \pmod{3},$

or equivalently,

$p \not\mid a^2+ab+b^2 \text{ (for no choice of } a \text{ and } b)\iff p \equiv 2 \pmod{3}?$

I'm totally stuck! Quite new in Number Theory.

Any help will be much appreciated.

• The first and second statements are not equivalent. Jan 12 '17 at 8:04
• Why not, please? @S.C.B. Jan 12 '17 at 8:05
• $p \implies q$ is not equivalent to ~$p \implies$ ~$q$. Jan 12 '17 at 8:06
• Generally, you are right. But this time, they are equivalent; provided $p \neq 3$. Let me make a proper edit in the question. Thanks Jan 12 '17 at 8:11
• Can you understand my answer? Jan 12 '17 at 8:13

You are slightly off, as since $$1^2+1 \times 1 +1^2 \equiv 0 \pmod 3$$ $p=3$ is posible as well. This can be proved as follows. $$a^2+ab+b^2 \equiv 0 \pmod p \implies (2a+b)^2+3b^2 \equiv 0 \pmod p$$ Thus, if $b^{*}$ is modulo inverse of $b$ modulo $p$, then we have that $$(2ab^{*}+1)^2 \equiv -3 \pmod p$$ So $-3$ is a quadratic residue of $p$, so we have that $p \equiv 1 \pmod 3$ or $p=3$. For why this is true, see here.