def prime_factors(n, primes_set): factors = [] while n != 1: if n in primes_set: break factor = brent(n) if factor not in primes_set: factors += prime_factors(factor, primes_set) else: factors.append(factor) while n % factor == 0: n /= factor if n != 1: factors.append(n) return factors
def prime_factors(n, primes_set): a = n factors = [] while n != 1: if n in primes_set: break factor = brent(n) if not factor in primes_set: factors += prime_factors(factor, primes_set) else: factors.append(factor) n /= factor if n != 1: factors.append(n) return set(factors)