Esempio n. 1
0
def answer():
    primes = sieve(32)
    d, x = 1, 1
    for prime in primes:
        d *= prime
        x *= prime - 1
        for n in range(2, prime):
            if x*n/(d*n - 1) < 15499/94744:
                return d*n
Esempio n. 2
0
def answer():
    found = 2
    primes = sieve(100)
    while found:
        perms = [1] + [0] * found
        for a in range(len(primes)):
            for b in range(primes[a], found + 1):
                perms[b] += perms[b - primes[a]]
        if perms[found] > 5000:
            return found
        found += 1
Esempio n. 3
0
def answer():
    count = set()
    primes = sieve(7071)
    for a in primes:
        for b in primes:
            d = a**4 + b**3
            if d >= 50000000:
                break
            for c in primes:
                e = c*c + d
                if e >= 50000000:
                    break
                count.add(e)
    return len(count)
Esempio n. 4
0
from euler_helpers import sieve

primes_up_to_20 = sieve(20)
prod_factors = [0]*21 # each element represents number of that index as a factor

for i in range(1,21):
    i_factors = [0]*21
    d = i
    while d not in primes_up_to_20:
        for prime in primes_up_to_20[1:]:
            if d%prime==0:
                i_factors[prime] += 1
                d /= prime
                break
    i_factors[d] += 1

    prod_factors = [ max([prod_factors[j],i_factors[j]]) for j in range(len(i_factors))]

print prod_factors
prod = reduce(lambda x,y:x*y, [i**prod_factors[i] for i in range(len(prod_factors)) ],1)

print 'Smallest product easily divisble by numbers 1-20  is %d' % (prod,)

Esempio n. 5
0
from euler_helpers import sieve
print sieve(150000)[10000]