Primes represented by x squared plus three y squared (source code)

= Primes represented by x squared plus three y squared
{title2=$p=x^2+3y^2\iff p=3\text{ or }p\equiv1\pmod3$}

A <prime number> $p$ has an <integer> representation $p=x^2+3y^2$ exactly when $p=3$ or $p\equiv1\pmod3$. The case three is $0^2+3\cdot1^2$, and two is impossible.

For necessity when $p\ne3$, reducing the equation <modulo> three gives $p\equiv x^2\pmod3$. The value cannot be zero, so it is one.

Conversely, for $p\equiv1\pmod3$, the <quadratic character of minus three> shows that $-3$ is a <quadratic residue> <modulo> $p$. Thus the <discriminant criterion for prime representation by a binary quadratic form> produces a positive definite form of discriminant $-12$ representing $p$. It is primitive because $p\nmid12$.

<Enumeration of reduced binary quadratic forms> gives only $[1,0,3]$ and $[2,2,2]$ at discriminant $-12$: the bound is $a\leq2$, and the integrality and boundary conditions leave those two. The second is imprimitive, so <proper equivalence> carries the representing form to $[1,0,3]$. This proves sufficiency. Examples are $7=2^2+3\cdot1^2$ and $13=1^2+3\cdot2^2$.