def count(max_len, curr_len, digit, counts): if digit > 9 or counts[-1] > 3: return 0 if curr_len >= max_len: counts = counts[:] counts[0] -= 1 return factorial(max_len) // product(factorial(i) for i in counts) res = count(max_len, curr_len + 1, digit, counts[:-1] + [counts[-1] + 1]) res += count(max_len, curr_len, digit + 1, counts + [0]) return res
from lib.utility import start_time, end_time, subsets, product from lib.prime import read_primes start_time() primes = read_primes(190) prods1 = [product(p) for p in subsets(primes[:len(primes) // 2])] prods2 = [product(p) for p in subsets(primes[len(primes) // 2:])] prods1.sort() prods2.sort() sqrt = product(primes) ** 0.5 i = 0 j = len(prods2) - 1 best = 0 while i < len(prods1) and j >= 0: current = prods1[i] * prods2[j] if current >= sqrt: best = min(current, best) j -= 1 elif current < sqrt: best = max(current, best) i += 1 print('Solution:', best % (10 ** 16)) end_time()
from lib.utility import start_time, end_time, product from lib.prime import prime_factors_table start_time() factors = prime_factors_table(10**5) a = [(n, product(set(factors[n]))) for n in range(0, 10**5 + 1)] E = sorted(a, key=lambda x: (x[1], x[0])) print('Solution:', E[10000][0]) end_time()
def num_solutions(n): uniq = set(prime_factors[n]) exponents = [2 * prime_factors[n].count(x) for x in uniq] num_divisors = product(1 + exp for exp in exponents) return (num_divisors + 1) // 2
from lib.utility import start_time, end_time, product from lib.prime import prime_factors_table from lib.partitions import partition from itertools import permutations start_time() limit = 120000 distinct_prime_factors = [set(x) for x in prime_factors_table(limit)] potential_rads = [(6, {2, 3})] for i, s in enumerate(distinct_prime_factors): if 2 < i < limit - 1 and i == product(s) and len(s) >= 3: potential_rads.append((i, s)) def combos(prime_factors): prime_factors = list(prime_factors) n = len(prime_factors) result = [] def rec(x, idx): if x >= limit: return if idx >= n: result.append(x) return rec(x * prime_factors[idx], idx) rec(x * prime_factors[idx], idx + 1) rec(1, 0) return sorted(result)