Exemplo n.º 1
0
def coprime(a, b):
    """Are integers a and b coprime?"""

    primes_a = pfactor(a)
    primes_b = pfactor(b)
    primes = [p for p in primes_a if p in primes_b]
    return bool(primes)
Exemplo n.º 2
0
Arquivo: e026.py Projeto: correl/euler
def coprime(a, b):
    """Are integers a and b coprime?"""

    primes_a = pfactor(a)
    primes_b = pfactor(b)
    primes = [p for p in primes_a if p in primes_b]
    return bool(primes)
Exemplo n.º 3
0
def factor(n):
    primes = pfactor(n)
    factors = [1, n]
    pow = {}
    for p in primes:
        if p not in pow.keys():
            pow[p] = 0
        pow[p] = pow[p] + 1
        factors.append(p**pow[p])

    for p in [f for f in factors if f > 1]:
        f = n / p
        if f not in factors:
            factors.append(n / p)
    combos = unique_combinations(factors, 2)
    for c in combos:
        f = product(c)
        if f < n and n % f == 0 and f not in factors:
            factors.append(f)

    if n not in factors:
        factors.append(n)

    return sorted(set(factors))
Exemplo n.º 4
0
Arquivo: e012.py Projeto: correl/euler
def factor(n):
    primes = pfactor(n)
    factors = [1, n]
    pow = {}
    for p in primes:
        if p not in pow.keys():
            pow[p] = 0
        pow[p] = pow[p] + 1
        factors.append(p**pow[p])
    
    for p in [f for f in factors if f > 1]:
        f = n / p
        if f not in factors:
            factors.append(n / p)
    combos = unique_combinations(factors, 2)
    for c in combos:
        f = product(c)
        if f < n and n % f == 0 and f not in factors:
            factors.append(f)
    
    if n not in factors:
        factors.append(n)
    
    return sorted(set(factors))