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