计算标准佩尔方程x^2-Dy^2=1的最小解的程序
while True:try:
a = 1
b = 0
c = input('请输入一个数字:')
c = eval(c)
d=c**0.5
a0=int(d)
a1=a0
r=d
p0=a0
q0=1
r=1/(r-a1)
a1=int(r)
p1=a0*a1+1
q1=a1
s=2
while int(1/(r-a1))!=2*a0 :
s+=1
r=1/(r-a1)
a1=int(r)
p2=a1*p1+p0
q2=a1*q1+q0
p0=p1
q0=q1
p1=p2
q1=q2
if s % 2 == 0 :
x0=p1
y0=q1
else :
x0=2*p1*p1+1
y0=2*p1*q1
print(x0,y0)
except:exit()