On the solution of $x^2+dy^2=m

On the solution of
2
2
x  dy  m.
Julius M. Basilla
Sophia University
Cornacchia ’ s Algorithm( 1908) for solving x 2  dy 2  4 p.
1. Initialization Step:
r1  t , t 2  d mod 4 p 
r0  4 p
2. Euclidean Step:
While r1  m,
2
r2  r0 mod r1  r0  r1
r1  r2
4 p  r12
3. If
 s 2 , then (r1 , s ) is a solution.
d
Otherwise, there is no solution.
The same algorithm can be used to solve
x 2  dy 2  m
for any integers, d , m
1
1  d  m.
Specifical ly, we claim that applying Cornacchia ' s
for all t , t 2  d mod m exhausts all the primitive
solutions of (1).
1. Every primitive solution of (1) is contained in some lattice
Lt : m,0, t ,1 Z ,
t 2  d mod m.
2. Applying Cornacchia ’ s algorithm with r0  m, r1  t ,
obtains a solution x0 , y0  of (1) contained in Lt ,
if Lt has a solution.
3. If Lt contains a primitive solution x0 , y0  of (1),
then x0 , y0   x0 , y0 .
In passing, we also claim that for d  1,
Cornacchia ’ s algorithm always yield a
solution, namely rk , rk 1  , where r
2
k 1
mr .
2
k
Lemma 1.
If  x0 , y0  is a primitive solution of (1),
then  x0 , y0  is contained in Lt  m,0 , t ,1 Z ,
for some t , t 2   d mod m .
Proof :
Clearly gcd  y0 , m   1. Thus there exist t satisfying
ty0  x0 mod m By the choice of t , it follows
x0 , y0   l m,0  y0 t ,1for some integer
and
0  t 2  d mod m .
l
Lemma 2.


Let u  u1 , u2 , v  v1 , v2  be generators of a lattice such that
0  u 2 , 0  v2 ,
v1  u1 , u1v1  0.

Then the vector w  w1 , w2  with the least w2  0,
and w1  v1 is given by
 

w  u  qv ,
 
Moreover, v , w
Z
 u 
q   1 .
 v1 
 
 u, v Z.
 

w  u  qv

v
No lattice point

u
u1
-v1
v1
Lemma 3
Let r0 , r1 be positive integers.
ri  qi ri 1  ri  2 ,
For 0  i  n  1, define
 ri 
qi  

r
 i 1 
P1  0;
P0  1;
Pi 1  qi Pi  Pi 1
Q1  1;
Q0  0; Qi 1  qi Qi  Qi 1
Then, for 0  i  n, we have
r0  Pi ri  Pi 1ri 1
(2)
ri 1  1 Pi r1  Qi r0  (3)
i
Propositio n 4
Let r0  m and r1  t , where t 2  d mod m . Construct the
finite sequences ri , Pi  as in Lemma 3. The diophantin e
equation (1) has a solution in Lt if and only if dPk21  m,
when rk21  m  rk2 .
Proof :
()It follows directly from (3) that rk2  dPk21  0mod m .
Thus, dPk21  rk2  m  rk2 mod m .
By uniqueness , we have dPk21  m  rk2 . Hence, rk , Pk 1 
is a solution in Lt .
 r4 , P3 
r3 , P2 
 r2 , P1 
t,1
 m,0
m
t
 r2
r2
r1  t
m
d
(x0,y0)
 rk , Pk 1 
rk 1 , Pk 2 
 rk 3 , Pk 2 
-rk-2
-rk-1 -rk
rk
m
rk-1
Proposition 5
Let t 2  1mod m ,
0  t  m . Set r0  m and r1  t and
2
construct the finite sequence {ri }, ri  qi ri 1  ri  2 , for 0  i  n  1,
where r0  r1    rn  1  rn 1  0.
If rk21  m  rk2 then m  rk2  rk21.
Proof :
Construct the finite sequence Pi  as in Lemma 3.
m  r0  Pn rn  Pn1rn1  Pn
rn1  qn1rn  rn1  qn1  2
m  Pn  qn1Pn1  Pn2  2Pn1
1  rn   1
Pn1r1  Qn1r0 
n 1
  1 Pn 1t mod m .
n 1
t  1 Pn1 mod m.
n
It follows that,
n  2k
Pn  r0  m
Inductively, we can show
Pn i  ri .
In particular,
m  r0  Pk rk  Pk 1rk 1
 rk2  rk21.
Pn 1  r1  t
Lemma 6
If d  1, then dPk2  m.
Propositio n 7
Let d  1 and t 2   d mod m . If  x, y , y  0
is a solution of (1) such that  x, y  in Lt , then
x, y    1k 1 rk , Pk 1 .
Pk
m
d
 rk , Pk 1 
rk 1 , Pk 2 
rk 3 , Pk 2 
-rk-2
-rk-1 -rk
rk
m
rk-1
Propositio n 8.
Let t 2  1mod m . If x, y , y  0 is a solution of
x 2  y 2  m such that  x, y  in Lt , then
x, y    1k 1 rk , rk 1 
or
x, y    1k rk 1, rk .
This proves that applying Cornacchia ' s algorithm
on all the square root t modulo m of  d , yields all
the primitive solution of x 2  dy 2  m.