Пример #1
0
from EulerUtils import genPrimes

limit = 50000000
lim1 = limit ** 0.33
lim2 = limit ** 0.25
primes = genPrimes(int(limit ** 0.5))
cubes = [i ** 3 for i in primes if i < lim1]
fourths = [i ** 4 for i in primes if i < lim2]

P = set()
for a in primes:
	a = a ** 2 
	for b in cubes:
		b += a
		if b > limit: break
		for c in fourths:
			c += b
			if c >= limit: break
			P.add(c)
print len(P)
Пример #2
0
from time import clock
from math import ceil
from math import log10
from EulerUtils import genPrimes

primes = genPrimes(100)

def up(n):
    return int(ceil(n))  

l = len(primes)
def sol(i, pLim):
    s = 0
    if i == len(primes):
        return 1
    else:
        p = primes[i]
        r = log10(p)
        lim = up((9 - pLim) / r)
        for x in range(lim):            
            s += sol(i + 1, pLim + x * r)
        return s
 
t = clock()   
print sol(0, 0) + 1
print clock() - t
                
Пример #3
0
from time import clock
from EulerUtils import genPrimes

t = clock()
primes = set(genPrimes(10000))
for prime in primes:
    if 1000 < prime < 3340:
        a = prime + 3330
        b = prime + 6660
        if a in primes and b in primes:
            if set(str(prime)) == set(str(a)) == set(str(b)):
                print str(prime) + str(a) + str(b), clock() - t
    
Пример #4
0
from time import clock
from EulerUtils import genPrimes

t = clock()
primes = genPrimes(1000)[3:]
pows = [10 ** i for i in range(1, 1000)]

m, n = 0, 0
for d in primes:
    p = [i for i in pows if (i - 1) % d == 0][0]
    if p > m:
        m, n = p, d
print clock() - t, n
Пример #5
0
from EulerUtils import genPrimes

lim = 1000000

sum = 0
sums = []
primes = genPrimes(lim)
for prime in primes:
    sum += prime
    if sum < lim:
        sums.append(sum)
    else:
        break

m, n = 0, 0
l = len(sums)
primes = set(primes) 
for i in range(l):
    for j in range(i + m, l):
        x = sums[j] - sums[i]
        if j - i > m and x in primes:
            n = x
            m = j - i
print m, n