Example #1
0
def sod(n):
    """Calculate sum of divisors of n"""
    prod = 1

    for k in primes.xprimes(int(n**0.5)+1):
        p = 1
        while n % k == 0:
            p = p*k+1
            n /= k
        prod *= p

    # n has a prime divisor > sqrt(n)
    if n > 1:
        prod *= 1+n

    return prod;
Example #2
0
def prime_factors(n, hint=None):
    """Return the prime factorization of in the form [(p,e), ...]"""
    if not hint: hint = int(n ** 0.5) + 1

    factors = []
    for p in primes.xprimes(hint):
        # Found all prime factors
        if n <= 1: break

        while 0 == n % p:
            if not factors or factors[-1][0] != p:
                factors.append([p,1])
            else:
                factors[-1][-1] += 1
            n /= p

    if n > 1:
        #print "Hint was too small, %s likely prime" % n
        if n < int(n ** 0.5) + 1:
            factors += prime_factors(n, int(n ** 0.5) + 1)
        else:
            factors += prime_factors(n, n)

    return factors
Example #3
0
File: 035.py Project: neilpa/euler
def gen_circular_primes(limit):
    return [p for p in primes.xprimes(limit) if circular(p)]
Example #4
0
File: 010.py Project: neilpa/euler
def solve(): 
    return sum(primes.xprimes(2000000))
Example #5
0
def xfactor(num):
    for prime in primes.xprimes(max=num):
        while num % prime == 0:
            yield prime
            num /= prime