def max_prime_factor(n): factors = [1] half = sqrt(int(n)) +1 #if we get here, we're too far ahead max_value = 1 for i in itertools.count(3, 2): #no use in checking the pairs... I know they won't be primes if i >= half: break if n % i == 0 and i % 5 != 0 and util.is_prime(i): #let's trim a couple right now too... max_value = i return max_value
def factors_of_a_number(n): prime_candidates = primes_util.erastot_sieve(int(round(n**0.5))) current = int(n) factors = {} while(current > 1): if primes_util.is_prime(current): prime = current if not current in factors: factors[current] = 1 else: factors[current] = factors[current]+1 break for prime in prime_candidates: if current % prime == 0: #if the remainder of the division is 0, it's a divisor if not prime in factors: factors[prime] = 1 else: factors[prime] = factors[prime]+1 current = current/prime break return factors