Пример #1
0
def pell(n):
    """
    A little reading reveals that we can use continued fraction
    convergents of the square root of n.
    http://en.wikipedia.org/wiki/Pell%27s_equation
    """

    cf = cf_sqrt(n)
    if len(cf) == 1:
        return None

    for h, k in convergents(cf):
        if h*h - n * k * k == 1:
            return (h,k)
Пример #2
0
def p065():
    n, d = itertools.islice(convergents(cf_e()), 99, 100).next()
    return sum((int(c) for c in str(n)))