# A condition for an odd prime to be represented by a binary quadratic form of a given discriminant

Let $f = ax^2 + bxy + cy^2$ be an integral binary quadratic form. We say $D = b^2 - 4ac$ is the discriminant of $f$. If $D < 0$ and $a > 0$, we say $f$ is positive definite. It is easy to see that $D \equiv 0$ (mod $4$) or $D \equiv 1$ (mod $4$). If $D$ is not a square integer and gcd($a, b, c) = 1$, we say $ax^2 + bxy + cy^2$ is primitive. Let $m$ be an integer. If $m = ax^2 + bxy + cy^2$ has a solution in $\mathbb{Z}^2$, we say $m$ is represented by $f$. If $m = ax^2 + bxy + cy^2$ has a solution $(s, t)$ such that gcd$(s, t) = 1$, we say $m$ is properly represented by $f$.

Let $D$ be a non-square integer such that $D \equiv 0$ (mod $4$) or $D \equiv 1$ (mod $4$). Let $n$ be an integer. We denote by $[n]$, the image of $n$ by the canonical map $\mathbb{Z} \rightarrow \mathbb{Z}/D\mathbb{Z}$. We claim that every element $(\mathbb{Z}/D\mathbb{Z})^\times$ is of the form $[m]$, where $m$ is a positive odd integer.

If $D \equiv 0$ (mod $4$), this is clear. So we assume $D \equiv 1$ (mod $4$). Every element $(\mathbb{Z}/D\mathbb{Z})^\times$ is of the form $[a]$, where $a \gt 0$ and gcd$(a, D) = 1$.

If $a$ is odd, let $m = a$.

If $a$ is even, let $m = a + nD$, where $n$ is an odd integer such that $a + nD \gt 0$ and we are done.

We define a map $\chi\colon (\mathbb{Z}/D\mathbb{Z})^\times\rightarrow \mathbb{Z}^\times = \{-1, 1\}$ as follows.

$\chi([m]) = \left(\frac{D}{m}\right)$, where $m$ is a positive odd integer which is relatively prime to $D$.

This is well defined by the proposition of this question. It is easy to see that $\chi$ is a group homomorphism.

Is the following proposition true? If yes, how do we prove it?

Proposition Let $D$ be a non-square integer such that $D \equiv 0$ (mod $4$) or $D \equiv 1$ (mod $4$). Let $\chi\colon (\mathbb{Z}/D\mathbb{Z})^\times\rightarrow \mathbb{Z}^\times = \{-1, 1\}$ be the map defined above. Let $p$ be an odd prime number which does not divide $D$. Then $\chi([p]) = 1$ if and only if $p$ is properly represented by a primitive form of discriminant $D$. Moreover, if $D \lt 0$ and $\chi([p]) = 1$, $p$ is properly represented by a positive definite primitive form of discriminant $D$.

Suppose $\chi([p]) = 1$. Then $\chi([p]) = \left(\frac{D}{p}\right) = 1$. By my answer to this question, $p$ is properly represented by a primitive form of discriminant $D$. Moreover, the proof of my answer shows that if $D \lt 0$, $p$ is properly represented by a positive definite primitive form of discriminant $D$.
Conversely suppose $p$ is properly represented by a primitive form of discriminant $D$. By this question, $D$ is a quadratic residue modulo $4p$. Hence $D$ is a quadratic residue modulo $p$. Hence $\chi([p]) = \left(\frac{D}{p}\right) = 1$.