def pellfermat2(d,n): result=[] for j in range(1,n+1): for i in range(1,n+1): if i**2==1+d*j**2: result.append((i,j)) return result[0]