def main(): lim = 1000 res = max_x = 0 squares = {x * x for x in range(2, int(sqrt(lim)) + 1)} for d in range(2, lim + 1): if d in squares: continue for num, den in convergent_fractions(quotients(d)): if num * num - d * den * den == 1: if num > max_x: max_x, res = num, d break return res
def main(): # e = [2; 1,2,1, 1,4,1, 1,6,1, ...] def quotients(): k = 2 yield k while True: yield from [1, k, 1] k += 2 convergents = convergent_fractions(quotients()) for _ in repeat(None, 100): num = next(convergents)[0] return sum(map(int, str(num)))
def main(): lim = 1000 res = max_x = 0 squares = {x*x for x in range(2, int(sqrt(lim)) + 1)} for d in range(2, lim+1): if d in squares: continue for num, den in convergent_fractions(quotients(d)): if num*num - d*den*den == 1: if num > max_x: max_x, res = num, d break return res