You are on page 1of 4

No. 8] Proc. Japan Acad., 81, Ser.

A (2005) 137

On the solution of x2 − dy 2 = ±m

By Julius M. Basilla∗) and Hideo Wada∗∗)


(Communicated by Shigefumi Mori, m. j. a., Oct. 12, 2005)

Abstract: An improvement of the Gauss’ algorithm for solving the diophantine equation
x2 − dy 2 = ±m is presented. As an application, multiple continued fraction method is proposed.
Key words: Quadratic form; diophantine equation; continued fraction method; prime
decomposition.

1. Introduction. For solving a given quad- 6 α


~0
ratic diophantine equation 
2 2
AX + BXY + CY + DX + EY + F = 0,
-
all we have to do is to solve one of the diophantine C
@
equations C @
C @
(1) x2 + dy 2 = m, C @
C R ( d, − d)
@
√ √
(2) x2 − dy 2 = ±m
C
where d and m are suitable positive √ integers and C
√ WC
d∈/ Q because the degenerate cases d ∈ Q and α
~ −1
m = 0 are easy (cf. [7, § 34, § 53]). There is a very ef-

ficient algorithm for solving (1) even if m is very large Fig. 1. m< d.
(cf. [1]). So in this paper, we shall treat the equa-
tion (2). Gauss gave an efficient algorithm (cf. [3,
zα0 and α
~ = y~
α−1 + z~α0 . Let Lt be
7, § 35]). Our algorithm is essentially the same as √ √
Gauss’ one, but a little more efficient and simpler. Lt = h(m, m), (−t + d, −t − d)iZ
Let x and y be a primitive solution of (2), = {y~
α−1 + z α~0 | y, z ∈ Z}.
namely a solution such that gcd(x, y) = 1. Then
gcd(y, m) = 1. So there exists an integer t such that Then α ~ is an element of Lt and for all β~ ∈ Lt , there
~ = y α~−1 + z α~0 and from (4)
exist y, z such that β
(3) x ≡ −ty (mod m).
From (2) and (3) we have ±m ≡ t2 y 2 −dy 2 (mod m). ββ 0 = (mz − ty)2 − dy 2
From gcd(y, m) = 1, we have ≡ (t2 − d)y 2 (mod m),
0
(4) t2 ≡ d (mod m). (5) ββ ≡ 0 (mod m).
√ √
Let ~ be (α, α0 ) = (x + dy, x − Therefore for solving the equation (2), we first cal-
√ α be x + dy and α
0
dy). Then αα = x − dy 2 = ±m. From (3) there
2 culate all t which satisfy (4). If we have a prime de-
exists an integer z such that x = mz − ty. So composition of m, we can calculate t very efficiently
√ √ (cf. [2]). Secondly we search α ~ 6= ~0 = (0, 0) in Lt
α = (mz − ty) + dy = mz + (−t + d)y. such that |αα | is the smallest. From (5), αα0 is a
0

Let α−1 be −t + d and α0 be m. Then α = yα−1 + multiple of m. If αα0 = ±m, then we get a solution.
If |αα0 | ≥ 2m, then there is no solution in Lt .
2000 Mathematics Subject Classification. 11D09, 11Y05,
11Y16. 2. Algorithm. Let t be a solution of (4). If
∗) Department of Mathematics, University of the Philip- t ≡ t (mod m) then t0 also satisfies (4). So we can
0

pines, Diliman, Quezon City 1101, Philippines. choose the smallest t such that
∗∗) Department of Mathematics, Sophia University, 7-1

Kioicho, Chiyoda-Ku, Tokyo 102-8554. α−1 = −t + d < α0 = m,
138 J.M. Basilla and H. Wada [Vol. 81(A),

0

α−1 = −t − d < −α00 = −m. 6
√ β~
Moreover if m < d, then we have 0 < α−1 (cf. >


Fig.
√ 1). √For example, when m = 1, then α−1 = 
 -
−[ d] + d. We define C
 0
αi−1
 C ~γ
(6) αi+1 = αi−1 + − 0 αi (i ≥ 0), C >


αi C 
α 0 C 
(7) βi = − i−1 , ki = [βi ]. C 
>
αi0 
C 
Let Fi be the Fibonacci sequence, namely F1 = F2 = WC
α
~
1, Fi+1 = Fi + Fi−1 . Then we have next theorem.
Theorem. Fig. 2. Next minimal element.

d+t 1
β0 = , βi+1 = . 3. Proof of the theorem. We call α ~ ∈ Lt
m βi − ki ~ 6= ~0 in Lt such thet
is minimal if there exists no β
The continued fraction expansion of β0 is |β| < |α|, |β 0 | < |α0 |. If |αα0 | is the smallest, then
of course α
~ is minimal. Therefore we shall search all
β0 = [k0 , k1 , k2 , . . . ]
minimal elements α ~ in Lt which are positive (namely
and there exist integers ai , bi , such that α > 0).
√ Let α
~ and β ~ be generators of Lt such that
d + bi
βi = , αi αi0 = (−1)i ai m. 0 < α < β, α0 β 0 < 0, |α0 | > |β 0 |
ai
√ ~ are minimal and the next
Even if α−1 < 0, if F2k ≥ m, then we have (cf. Fig. 2). Then α~, β
minimal element ~γ such that β < γ is
0 < α2k−1 < α2k < α2k+1 < · · · .
α0
 
γ =α+ − 0 β
Moreover there exists positive integer ` (< 2d) such β
that β2k = β2k+` . So ai are periodic. If ai = 1 for ~ and ~γ are also generators of
(cf. [8]). The vectors β
some i (2k ≤ i < 2k + `), then we have a solution αi
Lt and we have
in Lt and all solution in Lt are
0 < β < γ, β 0 γ 0 < 0, |β 0 | > |γ 0 |.
±αi+n` = ±(α2k+` /α2k )n αi , n ∈ Z.
~ and ~γ satisty the same conditions as α
Therefore β ~
If ai > 1 for all i (2k ≤ i < 2k + `), then there is no ~ From (6), we have
and β.
solution in Lt .
Example. Lt = h~
α−1 , α~0 i = hα~0 , α~1 i = hα~1 , α~2 i = · · · .
If we put ri = (−1)i αi0 , then
x2 − 295y 2 = ±5, √
t≡0 (mod 5), r−1 = t + d > m = r0 > 0.

0 < α−1 = 295 − 15 = 2.17 · · · < 5 = α0 , From (6), we have
0
√  
α−1 = − 295 − 15 < −5 = −α00 , ri+1 = ri−1 −
ri−1
ri .
√ ri
295 + 15
β0 = This is just the Euclidian Algorithm. So we have
5
= [6, 2, 3, 2, 1, 5, . . . ], r−1 > r0 > r1 > r2 > · · · > 0,
√  
295 + 17 ri−1 ri−1
β6 = , (8) βi = > 1, ki = ≥ 1,
1 √ ri ri
α6 = 2250 + 131 295, (9) αi+1 = αi−1 + ki αi .
22502 − 295 × 1312 = 5.
No. 8] On the solution of x2 − dy 2 = ±m 139

6 When α−1 > 0, we define k = 0. Then (10) is always


α
~0 valid. From (5) we have integers ai such that



(11) αi αi0 = (−1)i ai m.


α
~2
- We shall prove next Lemma.
Lemma. There are integers bi such that

α 0  α
−~ ~1
(12) 0
αi−1 αi = (−1)i−1 ( d + bi )m.

Proof. When i = 0,
α
~ −1 0 0

αi−1 αi = α−1 α0 = (−1)−1 ( d + t)m.
Fig. 3. α−1 < 0, α1 < 0. So b0 = t. If (12) is valid, then from (9)
√ αi0 αi+1 = αi0 (αi−1 + ki αi )
If m > d, then there is a possibility that α−1 0
< 0. We shall examine this case strictly. As k0 ≥ 1, = (αi−1 αi )0 + ki αi αi0

we have = (−1)i−1 (− d + bi )m + (−1)i ki ai m

α1 = α−1 + k0 α0 ≥ α−1 + α0 . = (−1)i ( d − bi + ki ai )m.
If α1 < 0, then α−1 < −α0 < 0. From 0 < α00 /α0 < So bi+1 = ki ai − bi .
0 0
α−1 /α−1 , we have 0 < α−1 /α−1 < α10 /α1 (cf. Fig. 3). From (7), (11), (12) we have
From 0 < α0 /α0 < α1 /α1 and −α00 < α10 < 0 we
0 0

0
have −α0 < α1 . From α00 /α0 < α10 /α1 and 0 < α20 αi−1 αi d + bi
βi = − 0 = .
we have 0 < α2 < α0 , α00 /α0 > α20 /α2 . Therefore if αi αi ai
α1 < 0 then we have
From (9) we have
α10 α0
α−1 < −α0 < α1 < 0 < α2 , > 2. 0
αi+1 0
αi−1
α1 α2 − = − − ki ,
αi0 αi0
Similarly if α2k−1 < 0 then we have
1
α−1 < −α0 < α1 < · · · < α2k−1 < 0 < α2k . = βi − [βi ],
βi+1
0

Let si be (−1)i αi . Then, α−1 d+t
β0 = − 0 = .
α0 m
s−1 > s0 > s1 > s2 > · · · > s2k−1 > 0.
If i ≥ 2k, then αi > 0. So ai > 0 follows from (11),
Recalling (9), we see
αi−1
si+1 = si−1 − ki si < si . 1 < βi , −1 < βi0 = − <0
αi
This is again the Euclidean Algorithm and follow from (8) and (10). Therefore we have
s2k−3 = k2k−2 s2k−2 + s2k−1 > 2s2k−1 = F3 · s2k−1 . √ √
d − bi d + bi
0< <1< , (i ≥ 2k).
Using induction we have ai ai
m = s0 > F2k · s2k−1 . From ai > 0, we have
√ √ √
Similarly we have 0 < bi < d, 0 < ai < d + bi < 2 d.
m = r0 > F2k · r2k−1 . Using pegion-hole principle, we can find i, j (2k ≤
0 i < j < 2k + 2d) such that βi = βj . From (9), we
As r2k−1 s2k−1 = α2k−1 α2k−1 ≡ 0 (mod m), we have

2 2
mF2k < m . Therefore if F2k ≥ m, we have have
αi+1 αi−1
(10) 0 < α2k−1 < α2k < α2k+1 < · · · . = + ki .
αi αi
140 J.M. Basilla and H. Wada [Vol. 81(A),


If 2k ≤ i, then 0 < αi−1 < αi < αi+1 . So we have has no solution, because β0 = 295 + 17 and ai are

αi+1
 1, 6, 21, 11, 9, 14, 5, 14, 9, 11, 21, 6, 1, . . . .
ki = , 5. Multiple continued fraction method.
αi
  We shall propose an improvement of continued frac-
αi+1
(13) αi−1 = αi+1 − αi (i ≥ 2k), tion metod (cf. [5]). When we want to decompose √ a
αi
large number d into prime factors, we expand d into
αi−1 αi+1

αi+1
 √ √
βi0 = − =− + , continued fraction. Namely from β0 = d + [ d],
αi αi αi we calculate βi . We want to get many ai which are
 
1 1 products of small primes. When some ai is ( pi )m,
Q
(14) βi0 = 0 + − 0 , (i ≥ 2k).
βi+1 βi+1 where pi are small primes but m is√a product of large
If 2k < i, then from (14) we have βi−1 = βj−1 . So primes, then we start from β̃0 = ( d + t)/m in par-
for some ` (1 ≤ ` < 2d) we have β2k = β2k+` . So allel with βi . There are many such m. From (11),
ai+` = ai (2k ≤ i), namely ai are periodic. (12), we have ai−1 ai = d − b2i . So we can use bi
Redefine αi−1 for i < 2k by (13). Then all pos- as t. From the√ continued  fraction expansion of β̃0 ,
itive minimal elements in Lt are α~i , i ∈ Z. Similarly we get β̃j = d + b̃j /ãj . We get many ãj which
we can prove for all i ∈ Z are products of small primes. So some product of
√ ai , ãj m becomes a square number and we can get a
α0 d + bi decomposition of d.
βi = − i−1 = = βi+` , αi αi0 = (−1)i ai m.
αi0 ai Acknowledgement. The authors thank the
Therefore if ai = 1 for some i (2k ≤ i < 2k + `), referee who suggested the use of the Fibonacci se-
we have a solution αi , and all solutions in Lt are quence for estimating k such that 0 < α2k−1 .
±αi+n` , n ∈ Z. From βi = βi+` , we have
−1 −1 References
αi+n` = 0 · · · 0 αi
βi+n` βi+1
 n [ 1 ] J.M. Basilla, On the solution of x2 + dy 2 = m,
α2k+` Proc. Japan Acad., 80A (2004), no. 5, 40–41.
= αi , n ∈ Z.
α2k [ 2 ] H. Cohen, A course in computational algebraic
number theory, Springer, Berlin, 1993.
If ai > 1 for all i such that 2k ≤ i < 2k + `, then [ 3 ] C.F. Gauss, Disquisiones Arithmeticae, Fleischer,
there is no solution in Lt . Therefore the theorem is Leipzig, 1801.
completely proved. √ √ [ 4 ] L.K. Hua, Introduction to number theory, Trans-
4. The case m < d. If m is less than d, lated from the Chinese by Peter Shiu, Springer,
then we have 0 < α−1 . Therefore we can take k = 0. Berlin, 1982.
If m = 1, then a` = a0 = 1, namely we have always [ 5 ] M.A. Morrison and J. Brillhart, A method of fac-
toring and the factorization of F7 , Math. Comp.
solutions. If m > 1 and (2) has a solution, then
29 (1975), 183–205.
there exists i (0
√ < i < `) such that ai = 1. Then [ 6 ] O. Perron, Die Lehre von dem Kettenbrüchen I,
0
we have√ β i = ( d + b i )/1, −1
√ < β i < 0. Therefore Teubner, Stuttgart, 1954.
bi = [ d] and β` = β0 = (√ d + √ t)/m. This means [ 7 ] T. Takagi, Lectures on the elementary theory of
that if we start from β0 = d + [ d], then for some numbers, 2nd ed., Kyoritsu-publication, Tokyo,
i, ai becomes m (Lagrange, cf. [4, 6, § 27]). If there 1971. (In Japanese).
[ 8 ] H. Wada, A note on the Pell equation, Tokyo J.
does not exist such i, then (2) has no solution. We
Math. 2 (1979), no. 1, 133–136.
need not calculate t. For example
x2 − 295y 2 = ±3

You might also like