Function: qfbcornacchia
Section: number_theoretical
C-Name: qfbcornacchia
Prototype: GG
Help: qfbcornacchia(D,n): Solve the equation
 x^2+Dy^2 = n in integers x and y where D > 0 and
 n is prime or 4 times a prime.
Doc: Solve the equation $x^2 + Dy^2= n$ in integers $x$ and $y$, where
 $D > 0$  and $n$ is prime or $4$ times a prime (in the latter case,
 $x$ and $y$ need not be coprime). This function is a special case of
 \kbd{qfbsolve} applied to the principal form in the imaginary quadratic
 order of discriminant $-4D$ (returning the solution with non-negative $x$
 and $y$). As its name implies, \kbd{qfbcornacchia} uses Cornacchia's algorithm
 and runs in time polynomial in $\log D$ and $\log p$, in fact quasi-linear
 in their max (through \kbd{halfgcd}; in practical ranges,
 \kbd{qfbcornacchia} should be two or three times faster than \kbd{qfbsolve}.
 \bprog
 ? qfbcornacchia(1, 113)
 %1 = [8, 7]
 ? qfbsolve(Qfb(1,0,1), 113)
 %2 = [7, -8]
 ? qfbcornacchia(1, 4*113) \\ no solution
 %3 = []
 ? qfbcornacchia(1, 4*109) \\ no solution
 %4 = [20, 6]
 ? p = 122838793181521; qfbcornacchia(24, p)
 %4 = [10547339, 694995]
 ? Q = Qfb(1,0,24); qfbsolve(Q,p)
 %5 = [10547339, 694995]
 ? for(i=1,10^5,qfbsolve(Q,p))
 time = 589 ms.
 ? for(i=1,10^5,qfbcornacchia(24,p)) \\ faster than qfbsolve
 time = 216 ms.
 @eprog
