(factors, n, limit, fail_max)
return done(n, d)
Return the value of n and either a 0 (indicating that factorization up
    to the limit was complete) or else the next near-prime that would have
    been tested.

    Factoring stops if there are fail_max unsuccessful tests in a row.

    If factors of n were found they will be in the factors dictionary as
    {factor: multiplicity} and the returned value of n will have had those
    factors removed. The factors dictionary is modified in-place.
Return the value of n and either a 0 (indicating that factorization up
    to the limit was complete) or else the next near-prime that would have
    been tested.
Return the value of n and either a 0 ( indicating that factorization up to the limit was complete ) or else the next near - prime that would have been tested .
def _factorint_small(factors, n, limit, fail_max):
    """
    Return the value of n and either a 0 (indicating that factorization up
    to the limit was complete) or else the next near-prime that would have
    been tested.

    Factoring stops if there are fail_max unsuccessful tests in a row.

    If factors of n were found they will be in the factors dictionary as
    {factor: multiplicity} and the returned value of n will have had those
    factors removed. The factors dictionary is modified in-place.

    """

    def done(n, d):
        """return n, d if the sqrt(n) wasn't reached yet, else
           n, 0 indicating that factoring is done.
        """
        if d*d <= n:
            return n, d
        return n, 0

    d = 2
    m = trailing(n)
    if m:
        factors[d] = m
        n >>= m
    d = 3
    if limit < d:
        if n > 1:
            factors[n] = 1
        return done(n, d)
    # reduce
    m = 0
    while n % d == 0:
        n //= d
        m += 1
        if m == 20:
            mm = multiplicity(d, n)
            m += mm
            n //= d**mm
            break
    if m:
        factors[d] = m

    # when d*d exceeds maxx or n we are done; if limit**2 is greater
    # than n then maxx is set to zero so the value of n will flag the finish
    if limit*limit > n:
        maxx = 0
    else:
        maxx = limit*limit

    dd = maxx or n
    d = 5
    fails = 0
    while fails < fail_max:
        if d*d > dd:
            break
        # d = 6*i - 1
        # reduce
        m = 0
        while n % d == 0:
            n //= d
            m += 1
            if m == 20:
                mm = multiplicity(d, n)
                m += mm
                n //= d**mm
                break
        if m:
            factors[d] = m
            dd = maxx or n
            fails = 0
        else:
            fails += 1
        d += 2
        if d*d > dd:
            break
        # d = 6*i - 1
        # reduce
        m = 0
        while n % d == 0:
            n //= d
            m += 1
            if m == 20:
                mm = multiplicity(d, n)
                m += mm
                n //= d**mm
                break
        if m:
            factors[d] = m
            dd = maxx or n
            fails = 0
        else:
            fails += 1
        # d = 6*(i+1) - 1
        d += 4

    return done(n, d)
def _factorint_small ( factors , n , limit , fail_max ) : def done ( n , d ) : """return n, d if the sqrt(n) wasn't reached yet, else
           n, 0 indicating that factoring is done.
        """ if d * d <= n : return n , d return n , 0 d = 2 m = trailing ( n ) if m : factors [ d ] = m n >>= m d = 3 if limit < d : if n > 1 : factors [ n ] = 1 return done ( n , d ) # reduce m = 0 while n % d == 0 : n //= d m += 1 if m == 20 : mm = multiplicity ( d , n ) m += mm n //= d ** mm break if m : factors [ d ] = m # when d*d exceeds maxx or n we are done; if limit**2 is greater # than n then maxx is set to zero so the value of n will flag the finish if limit * limit > n : maxx = 0 else : maxx = limit * limit dd = maxx or n d = 5 fails = 0 while fails < fail_max : if d * d > dd : break # d = 6*i - 1 # reduce m = 0 while n % d == 0 : n //= d m += 1 if m == 20 : mm = multiplicity ( d , n ) m += mm n //= d ** mm break if m : factors [ d ] = m dd = maxx or n fails = 0 else : fails += 1 d += 2 if d * d > dd : break # d = 6*i - 1 # reduce m = 0 while n % d == 0 : n //= d m += 1 if m == 20 : mm = multiplicity ( d , n ) m += mm n //= d ** mm break if m : factors [ d ] = m dd = maxx or n fails = 0 else : fails += 1 # d = 6*(i+1) - 1 d += 4 return done ( n , d )