def solve(): """ >>> solve() 428570 """ best = 2 / 5, 2, 5 primer = CachedPrimer() for denominator in range(2, 1000001): if denominator % 1000 == 0: print(denominator) denominator_prime_factors = primer.prime_factors(denominator).keys() numerator = best_numerator_using_binary(denominator) assert numerator / denominator < TARGET def hcf_is_1(numerator): common_factors = (primer.prime_factors(numerator).keys() & denominator_prime_factors) return not common_factors while numerator / denominator > best[0] and not hcf_is_1(numerator): numerator -= 1 current = numerator / denominator assert current < TARGET if current > best[0]: best = current, numerator, denominator # Ended up using the code from both wrong solutions. Cool! return best[1] # (0.42857128571385716, 428570, 999997)
def solve(): """ >>> solve() 142913828922 """ primer = CachedPrimer() known_primes = primer.primes_up_to(2000000) return sum(known_primes)
def solve(): """ >>> solve() 104743 """ primer = CachedPrimer() primes = primer.primes_up_to(stop_at_n_primes=10001) return primes[-1]
def solve(): """ >>> solve() 232792560 """ PRIMER = CachedPrimer() factors = collections.Counter() for i in range(1, 21): for factor, power in PRIMER.prime_factors(i).items(): factors[factor] = max(power, factors[factor]) return math.prod(factor**power for factor, power in factors.items())
def solve(): """ >>> solve() 76576500 """ primer = CachedPrimer() number = 1 print( candidates, smallest_possible_500_factors, primer.factors_count(smallest_possible_500_factors), ) index = 1 best_count = 0 while (count := primer.factors_count(number)) <= 500: index += 1 number += index if count >= best_count: best_count = count print(number, best_count)
import collections import itertools import math import wrapt_timeout_decorator from common.primer import CachedPrimer PRIMER = CachedPrimer() # def smallest_possible_500_factors(): # INCORRECT # first_500_primes = PRIMER.primes_up_to(stop_at_n_primes=500) # best = math.inf # prime_count = 500 # while prime_count > 1: # factors = itertools.chain(*zip(*(first_500_primes for _ in range(prime_count)))) # candidate = 1 # used_factors = collections.Counter() # while math.prod(used_factors.values()) < 500: # factor = next(factors) # used_factors[factor] += 1 # candidate *= factor # if prime_count == 4: # print(factor) # prime_count -= 1 # best = min(candidate, best) # return best
from common.primer import CachedPrimer def sum_digits(n): return sum(int(char) for char in str(n)) PRIMER = CachedPrimer() generators = [] for n in range(1, 100000001): last_digit = n % 10 # if n > 6 and not last_digit in {2, 8, 0}: # continue if all( PRIMER.is_prime(factor + n // factor) for factor in PRIMER.factors(n)): generators.append(n) print(n, last_digit in {2, 8, 0}, PRIMER.prime_factors(n))