If $a$ and $b$ are integers such that $9$ divides $a^2 + ab + b^2$ then $3$ divides both $a$ and $b$. If $a$ and $b$ are integers such that $9$ divides $a^2 + ab + b^2$ then show that $3$
divides both $a$ and $b$.

can anyone tell me please how to solve these types of problem oe which formula is required
 A: As Glen has shown,  $9\mid \{(a-b)^2+3ab\}$
$\implies 3\mid \{(a-b)^2+3ab\}\implies 3\mid(a-b)^2$
$\implies 3\mid(a-b)\implies 9\mid(a-b)^2$
$\implies 9\mid3ab\implies 3\mid ab$
But if $3$ divides $a,3$ must  divide $b$ and conversely as $3\mid(a-b)$
A: Starter: Since $a^3-b^3=(a-b)(a^2+ab+b^2)$, and by Fermat'little theorem, we conclude that, under our condition, $a\equiv b\pmod 3$.
Suppose the contrary: $a, b$ are relatively prime to $3$. So $a=3k\pm1, b=3l\pm1$. Then $a^2=9k^2\pm6k+1$,
$b^2=9l^2\pm6l+1$,
$ab=9kl\pm3(k+l)+1$.
Summing together, we find: $a^2+ab+b^2=9(k^2+l^2+kl\pm k\pm l)+3$, which is not divisible by $9$, a contradiction. Therefore $a$ and $b$ are both divisible by $3$.
If any mistakes are presented, tell me. Thanks in advance.  
A: The divisibility is equivalent to $$3^2\mid 4(x^2+xy+y^2)=(2x+y)^2+3y^2$$. Since $3\mid 3y^2$ then $3\mid (2x+y)^2$. But $(2x+y)^2$ is a square so $3^2\mid (2x+y)^2$, implying that $3^2\mid 3y^2$, i.e. $3\mid y$. Together with $3\mid 2x+y$ we get also $3\mid x$.
A: Whenever you have an "$x$ divides $y$" problem, start by stating it in modular form.
$$
a^2+ab+b^2 \equiv 0 \mod 9
$$
Now, we can also write this as
$$
a^2-2ab+b^2 \equiv -3ab \mod 9
$$
Therefore, we must have that $(a-b)^2\equiv 0 \pmod3$, and this can only be satisfied if $a\equiv b\pmod 3$.
So let $b=a+3k$ and substitute back into the original equation:
$$
a^2+a^2+3ak+a^2+6ak+9k^2\equiv 0 \mod 9
$$
Which can be simplified to
$$
3a^2 + 9ak + 9k^2 \equiv 0 \mod 9\\
3a^2 \equiv 0 \mod 9\\
a^2 \equiv 0 \mod 3
$$
And this is only satisfied if $a\equiv 0\pmod3$. And because $a\equiv b\pmod3$, we also have that $b\equiv 0\pmod3$. So 3 divides $a$ and 3 divides $b$.
