Esempio n. 1
0
def main(verbose=False):
    MAX_n = 10 ** 6 - 1
    distinct_solutions = 10
    PRIMES = sieve(int(sqrt(MAX_n)) + 1)
    factor_hash = {}

    count = 0
    for n in range(1, MAX_n + 1):
        factor_list = factors(n, factor_hash, PRIMES)
        if len(num_solutions(factor_list)) == distinct_solutions:
            count += 1
    return count
Esempio n. 2
0
def all_values_on_form(form, value):
    """
    Returns all lattice points (not necessarily coprime)
    that produce the desired value on the form

    Given the recurrence for the form, these values
    can serve to determine *all* solutions for
    the given value due to the repeating nature
    of the infinite river
    """
    factor_list = factors(value)
    valid_factors = [factor for factor in factor_list
                     if is_power(value/factor, 2)]

    roots = all_positive_roots(form)
    found = set()
    for root in roots:
        candidates = seek_up_to_val(root, value)
        to_add = [candidate for candidate in candidates
                  if candidate[1] in valid_factors] + \
                 [candidate for candidate in root
                  if candidate[1] in valid_factors]
        found.update(to_add)
    found = list(found)

    # We may get some duplicates from since when we include
    # values from the river, we don't check that they come from
    # a different iteration of the river
    x_mult, y_mult, _ = get_recurrence(form)
    checked = found[:]
    for candidate in found:
        coords, val = candidate
        next_x = sum(operator.mul(*pair) for pair in zip(coords, x_mult))
        next_y = sum(operator.mul(*pair) for pair in zip(coords, y_mult))
        if ((next_x, next_y), val) in found:
            checked.remove(((next_x, next_y), val))

    # Finally we must scale up factors to account for
    # the reduction by a square multiple
    result = []
    for cell in checked:
        (x, y), val = cell
        if val < value:
            ratio = int(sqrt(value/val))
            x *= ratio
            y *= ratio
        result.append((x,y))

    return result