* Copyright (c) 1993 David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
* Solve Pell's equation; Returns the solution X to: X^2 - D * Y^2 = 1.
* Type the solution to pells equation for a particular D.
print "D=":D:" is square";
Y = isqrt((X^2 - 1) / D);
print X : "^2 - " : D : "*" : Y : "^2 = " : X^2 - D*Y^2;
* Function to solve Pell's equation
* Returns the solution X to:
local R, Rp, U, Up, V, Vp, A, T, Q1, Q2, n;
Q1 = isqrt(Q2^2 * D + 1);
print "pellx(D) defined";