Given quadratic diophantine equation $x^2+dy^2=m$ where $d,m> 0$ and $d$ is square-free, Cornacchia's algorithm: https://en.wikipedia.org/wiki/Cornacchia%27s_algorithm, solves the problem in polynomial time by firstly finding a square root $s$ of $-d$ modulo $m$, i.e solve $s^2\equiv -d \mod m$ and then performing a gcd-like step until some certain condition is satisfied. If the condition is not satisfied, we try another square root of $-d$ until we find a solution or exhaust all square roots and in this case no primitive solution exists.
The problem with this approach is that we have might have to try all $2^{\omega(m)}$ square roots until we find a solution, and if $m$ has "too many" prime factors the running time becomes exponential in $\log m$ (as $\omega(m)=O( \frac{\log m}{\log\log m})$).
Lets say we have the factorization of $m$ so we can extract square roots of $-d\pmod m$ easily. Is there a way to circumvent the issue of going through all square roots whem $m$ is highly composite? Its worthy to note that I’m also interested in the quantum setting. And I was honestly looking at how one can reduce this problem to an instance of the hidden subgroup problem which can be solved in quantum polynomial-time. I know Grover’s algorithm provides a quadratic speedup, but that’s still not good enough. Would really appreciate any assistance on that!