Exemplo n.º 1
0
def Prime_div(num,Prime,divisors):
    """ Recursively Finds the prime divisors of a given number,

    Args:
        num (int): Number whose Prive divisors will be calculated
        Prime (Prime) : An instance of the Prime class used to generate primes
        divisors (list): A list representing the divisors found so far        
    
    """
    if divisors == []: #if this is the first call add one to list all numbers div by 1
        divisors.append(1)
    
    if Prime.isPrime(num):#base case. when prime number is found we have found all Prime divisors
        temp = divisors        
        divisors.append(num)
        
        
        return divisors
    else:# testing case. If we have not found our base prime, then we keep calling the function
        Prime.reset()
        factor = Prime.nextPrime()
        found = False#Set to false in each call 
        while factor < num/2 and not found:
            if num%factor == 0:
                divisors.append(factor)#Appends a found prime divisor to our list
                found = True
            if not found:
                factor = Prime.nextPrime()#Cycles through prime list until we find a prime the number is divisible by
        return Prime_div(num/factor,Prime,divisors)