project_euler.problem_124.sol1 ============================== .. py:module:: project_euler.problem_124.sol1 .. autoapi-nested-parse:: Project Euler Problem 124: https://projecteuler.net/problem=124 Ordered Radicals Functions --------- .. autoapisummary:: project_euler.problem_124.sol1.generate_n project_euler.problem_124.sol1.generate_primes project_euler.problem_124.sol1.generate_rads project_euler.problem_124.sol1.solution Module Contents --------------- .. py:function:: generate_n(factors: list[int], n_max: int, n: int, res: set[int]) Generates all numbers n that can be constructed out of 'factors', with any multiplicity, but that do no exceed 'n_max'. >>> generate_n([2], 10, 1, set()) .. py:function:: generate_primes(n: int) -> list[int] Calculates the list of primes up to and including n. >>> generate_primes(6) [2, 3, 5] .. py:function:: generate_rads(factors_all: list[int], n_max: int, n: int, res: dict, factors_prev: list[int]) Generates all rads and associated factors, e.g., rad = factor_1 * ... * factor_k. Output is stored in 'res' dict argument. >>> generate_rads([2], 10, 1, {}, []) .. py:function:: solution(n_max: int = 100000, k: int = 10000) -> int Loops over sorted 'rads' and generates all numbers 'n' for rad. Keeps track of total number of n, and when k falls inside some rad, it sorts all 'n' for it and picks up associated n. >>> solution(10, 6) 9 >>> solution(10, 9) 7