コード例 #1
0
ファイル: no271.py プロジェクト: dhermes/project-euler
def main(verbose=False):
    product = 13082761331670030
    factors = prime_factors(product)

    candidate_lists = []
    for factor in factors:
        candidate_lists.append([(factor, root)
                                for root in find_cube_roots(factor)])

    result = list(i_product(*candidate_lists))

    coprime_units = {}
    for factor in factors:
        _, multiplier = extended_euclid(factor, product / factor)
        coprime_units[factor] = multiplier * (product / factor)

    vals = []
    for pairing in result:
        count = 0
        for prime, residue in pairing:
            count += residue * coprime_units[prime]
        count = count % product
        vals.append(count)

    return sum(vals) - 1  # 1 is in there as (1,1,...,1)
コード例 #2
0
ファイル: no160.py プロジェクト: dhermes/project-euler
def unit_a_zero_b(a, b):
    _, multiplier = extended_euclid(a, b)
    return (multiplier * b) % (a * b)