\\ \\ solve Pell's Equation |x^2-Dy^2|=1 \\ D is square-free \\ pell(d,pr)= { local(bb,b,len,m,x,y,z,x2,y2); if(pr>28, default(realprecision,pr) ); bb=contfrac(sqrt(d)); len=length(bb); for(i=1,len, b=vecextract(bb,2^i-1); \\ print(b); m=contfracpnqn(b); \\ print("m=",m); x=m[1,1]; y=m[2,1]; z=x^2-d*y^2; \\ print("[x,y]=",[x,y,z]); if(z==1, \\ print("i=",i); \\ print("x=",x); \\ print("y=",y); \\ print("x^2-",d,"*y^2=",z); return([x,y,z]) ); if(z==-1, x2=x*x+d*y*y; y2=2*x*y; return([x2,y2,1]) ) ); return([]) } \\ \\ find (x,y) \in N \\ x^2-Dy^2=-1 or 1 \\ pell0(d,pr)= { local(bb,b,len,m,x,y,z); if(pr>28, default(realprecision,pr) ); bb=contfrac(sqrt(d)); len=length(bb); for(i=1,len, b=vecextract(bb,2^i-1); \\ print(b); m=contfracpnqn(b); \\ print("m=",m); x=m[1,1]; y=m[2,1]; z=x^2-d*y^2; \\ print("[x,y]=",[x,y,z]); if(abs(z)==1, \\ print("i=",i); \\ print("x=",x); \\ print("y=",y); \\ print("x^2-",d,"*y^2=",z); return([x,y,z]) ) ); return([]) } findpell(n1,n2,pr)= { local(d2,pp,pre); for(d=n1,n2, d2=sqrtint(d); if(d2*d2