Example #1
0
def pfactors(num, l=[]):
    if (num == 1): return [1]

    if len(l) == 0: l = get_list()
    loc, found = search.binary_low(l, num)
    e = l[-1]


    # If number is in list
    # It means the number is prime
    # Hence it is the only prime factor
    if (found): return [num]

    # Get all primes below num
    ll = primes(num, l)
    return [n for n in ll if(num % n == 0)]
Example #2
0
def primes(num, l=[]):
    
    if len(l) == 0: l = get_list()

    # Check to see if a sublist can be created
    e = l[-1]
    if (num < e):
        res = search.binary_low(l, num)
        return l[:res[0]+1]

    e = 6*(ceil(e/6))

    lim = num + 1
    # Extend the current list
    for n in range(e, lim, 6):
        m = n - 1
        if isprime(m, l): l.append(m)
        m = n + 1
        if isprime(m, l): l.append(m)

    # Save to pickle
    set_list(l)

    return l