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() 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())
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))