Example #1
0
def p064():
    LIMIT = 10000
    count = 0
    for i in xrange(2,LIMIT+1):
        cf = cf_sqrt(i)
        if len(cf) > 1 and len(cf[1]) % 2:
            count += 1
    return count
Example #2
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)