Solve 73 in Python.

This commit is contained in:
2019-08-01 21:15:14 -04:00
parent 4c93d34c26
commit d3c7dcd66a
2 changed files with 29 additions and 25 deletions

View File

@@ -1,4 +1,3 @@
from collections import namedtuple
from lib_prime import primes
from functools import lru_cache
@@ -14,28 +13,6 @@ def relative_primes_count_factors(n, factors):
return n // d
Fraction = namedtuple("Fraction", ["n", "d"])
# Procedures that were not actually helpful
def get_farey_series_length(f_min, f_max, d_max):
if f_min.d + f_max.d > d_max:
return 0
f_med = Fraction(f_min.n + f_max.n, f_min.d + f_max.d)
l_min = get_farey_series_length(f_min, f_med, d_max)
l_max = get_farey_series_length(f_med, f_max, d_max)
return l_min + 1 + l_max
def get_farey_series(f_min, f_max, d_max):
if f_min.d + f_max.d > d_max:
return []
f_med = Fraction(f_min.n + f_max.n, f_min.d + f_max.d)
l_min = get_farey_series(f_min, f_med, d_max)
l_max = get_farey_series(f_med, f_max, d_max)
return l_min + [f_med] + l_max
def prime_factors_unique(n, primes_list, primes_set):
if n in primes_set:
return [n]