def special_num_factors(a, b, hash_): factors = (prime_factors(a, unique=False, hash_=hash_) + prime_factors(b, unique=False, hash_=hash_)) factors = list_frequencies(factors) prod = 1 for factor in factors: prod *= factor[1] + 1 return prod
def main(verbose=False): product = 13082761331670030 factors = prime_factors(product) candidate_lists = [] for factor in factors: candidate_lists.append([(factor, root) for root in find_cube_roots(factor)]) result = list(i_product(*candidate_lists)) coprime_units = {} for factor in factors: _, multiplier = extended_euclid(factor, product / factor) coprime_units[factor] = multiplier * (product / factor) vals = [] for pairing in result: count = 0 for prime, residue in pairing: count += residue * coprime_units[prime] count = count % product vals.append(count) return sum(vals) - 1 # 1 is in there as (1,1,...,1)
def main(verbose=False): prime_factors_hash = {} MINIMUM_SOLUTIONS = 4*(10**6) # P^k < 10**7 (10 mil) powers = [power_up_to_digits(prime, 7) for prime in [3, 5, 7]] products = [reduce(operator.mul, triple) for triple in list(i_product(*powers))] products = [product for product in sorted(products) if product > 2*MINIMUM_SOLUTIONS][:20] PRIMES = sieve(100) max_prod = 10**21 res = [] for product in products: factors = prime_factors(product, unique=False, hash_=prime_factors_hash) factors = [(factor - 1)/2 for factor in factors][::-1] curr_prod = 1 for i, exp in enumerate(factors): curr_prod = curr_prod*(PRIMES[i]**exp) if curr_prod < max_prod: max_prod = curr_prod return max_prod
def main(verbose=False): # Find the first four consecutive integers to have four distinct # primes factors. What is the first of these numbers? factor_hash = {1: [], 2: [2]} # Smallest product of 4 primes is 2*3*5*7 = 210 # We need to update the hash to get to this point for i in range(3,210 + 1): prime_factors(i, hash_=factor_hash) smallest = 210 # The smallest integer of the four num_factors = [ len(prime_factors(smallest + i, unique=True, hash_=factor_hash)) for i in range(4) ] while num_factors != [4,4,4,4]: smallest = increment(smallest, num_factors) num_factors = [ len(prime_factors(smallest + i, unique=True, hash_=factor_hash)) for i in range(4) ] return smallest
def main(verbose=False): return max(prime_factors(600851475143))