Cornacchia's algorithm

From testwiki
Jump to navigation Jump to search

Template:Short description In computational number theory, Cornacchia's algorithm is an algorithm for solving the Diophantine equation x2+dy2=m, where 1d<m and d and m are coprime. The algorithm was described in 1908 by Giuseppe Cornacchia.[1]

The algorithm

First, find any solution to r02d(modm) (perhaps by using an algorithm listed here); if no such r0 exist, there can be no primitive solution to the original equation. Without loss of generality, we can assume that Template:Math (if not, then replace Template:Math with Template:Math, which will still be a root of Template:Math). Then use the Euclidean algorithm to find r1m(modr0), r2r0(modr1) and so on; stop when rk<m. If s=mrk2d is an integer, then the solution is x=rk,y=s; otherwise try another root of Template:Math until either a solution is found or all roots have been exhausted. In this case there is no primitive solution.

To find non-primitive solutions Template:Math where Template:Math, note that the existence of such a solution implies that Template:Math divides Template:Mvar (and equivalently, that if Template:Mvar is square-free, then all solutions are primitive). Thus the above algorithm can be used to search for a primitive solution Template:Math to Template:Math. If such a solution is found, then Template:Math will be a solution to the original equation.

Example

Solve the equation x2+6y2=103. A square root of −6 (mod 103) is 32, and 103 ≡ 7 (mod 32); since 72<103 and 103726=3, there is a solution x = 7, y = 3.

References

Template:Number theoretic algorithms