예제 #1
0
def primalHappiness(n): # find happy primes up to n, return list of them
    fillHappiness(n)
    primenumbers=primes(n)
    happyPrimes=[]
    for i in happiness:
        if i in primenumbers:
            happyPrimes.append(i)
    return happyPrimes
예제 #2
0
def primeFactors(n):
    """a list of prime factors of n"""

    result = []    
    upper_bound = 1 +int(n**0.5) # only have to seek to the square root 
    searchList = primes(upper_bound)
    
    for divisor in searchList:
        if divides(divisor, n):
            result.append(divisor)
            result += primeFactors(int(n // divisor))
            break
    # no factors found, so assume prime.
    if result == []:
        result.append(n)
    return result