Speeding up an algorithm for finding the number of distinct lines
You can improve your divisors function:

Version 1: (not includes n)

def divisors(n):
    """Return the divisors of n (including 1)"""
    if(n == 1):
        return (0)

    divs = set([1])
    r = floor(sqrt(n))
    if(r**2 == n):
        divs.add(r)

    f = 2
    step = 1
    if(n &amp; 1 == 1):
        f = 3
        step = 2

    while(f &lt;= r):
        if(n % f == 0):
            divs.add(n/f)
            divs.add(f)
        f = f + step

    return sorted(divs)


Version 2: (includes n) from here

def divisors2(n) :
    """
    Generates all divisors, unordered, from the prime factorization.
    """
    factors = factorI(n)
    ps = sorted(set(factors))
    omega = len(ps)

    def rec_gen(n = 0) :
        if n == omega :
            yield 1
        else :
            pows = [1]
            for j in xrange(factors.count(ps[n])) :
                pows += [pows[-1] * ps[n]]
            for q in rec_gen(n + 1) :
                for p in pows :
                    yield p * q

    for p in rec_gen() :
        yield p


where factorI is:

def factorI(n):
    """Returns the factors of n."""
    lst = []
    num = int(n)
    if(num &amp; 1 == 0):
        lst.append(2)
        num /= 2
        while(num &amp; 1 == 0):
            lst.append(2)
            num /= 2

    factor = 3
    maxFactor = sqrt(num)
    while num&gt;1 and factor &lt;= maxFactor:
        if(num % factor == 0):
            num /= factor
            lst.append(factor)
            while(num % factor == 0):
                lst.append(factor)
                num /= factor
            maxFactor = sqrt(num)
        factor += 2

    if(num &gt; 1):
        lst.append(num)
    return lst


For efficiency reasons you could also make generator functions.