Пример #1
0
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
Пример #2
0
#!/usr/bin/env python

from fractions import Fraction
from pe_tools import cf_to_rational

def sum_of_digits(n):
    return sum(map(int, str(n)))


if __name__ == '__main__':
    e = [2]
    for i in range(1,40):
        e += [1, 2*i, 1]
    c = cf_to_rational(e[:100])
    print "{}".format(sum_of_digits(c.numerator))