How to find a quadratic form that represents a prime?
Given $a,b,c,p\in\Bbb N$ with $b^2-4ac<0$ and $p$ is a prime with $\bigg(\frac{b^2-4ac}p\bigg)=1$ and $p\nmid b^2-4ac$, then there is at least one primitive form of discrimant $b^2-4ac$ that represents $p$. What is a good procedure to find that form?
yeah, $\Delta = b^2 - 4 a c$ is negative and $(\Delta|p) = 1$ for odd prime $p$ not dividing $\Delta.$
Solve $$ \beta^2 \equiv \Delta \pmod {4p} $$ where the extra $4$ means you take either $\beta$ or $p-\beta,$ it is really just a mod 2 condition, even or odd.
If $p$ is large, to solve the initial $ \beta^2 \equiv \Delta \pmod p, $ you may need either
https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm
https://en.wikipedia.org/wiki/Cipolla%27s_algorithm
Now you have $$ \beta^2 = \Delta + 4pt, $$ $$ \beta^2 - 4pt = \Delta. $$ Therefore $$ \langle p, \beta, t \rangle $$ is a form that represents $p$ with the correct discriminant. Reduce it by standard Gaussian reduction, which is very fast, about as fast as the Euclidean algorithm. the resulting "equivalent" form represents $p,$ and reversing the steps shows you how to represent it. That involves keeping track of some two by two matrices, all in $SL_2 \mathbb Z$.