def solve_pells_for_x(d): i = 1 while True: cf = repeating_cf(continued_fraction_sqrt(d)) finite_cf = [cf.next() for _ in range(i)] rational = cf_to_rational(finite_cf) if test_pells_equation(rational.numerator, d, rational.denominator): return rational.numerator i += 1
#!/usr/bin/env python import math import pe_tools from pe_tools import continued_fraction_sqrt if __name__ == "__main__": total = 0 for i in range(1, 10000): if not pe_tools.is_square(i): l = len(continued_fraction_sqrt(i)) - 1 if l % 2 == 1: total += 1 print str(total)