예제 #1
0
#!/usr/bin/python
import time, math
from Functions.Functions import Functions

start = time.time()
print "Sum: {}".format(sum(Functions.sieve(2000000)))
print "Done in: " + str(time.time() - start)
예제 #2
0
	while i > 0 and arr[i - 1] >= arr[i]:
		i -= 1
	if i <= 0:
		return False
	
	# Find successor to pivot
	j = len(arr) - 1
	while arr[j] <= arr[i - 1]:
		j -= 1
	arr[i - 1], arr[j] = arr[j], arr[i - 1]
	
	# Reverse suffix
	arr[i : ] = arr[len(arr) - 1 : i - 1 : -1]
	return True

primes = [i for i in Functions.sieve(10000) if i > 1000]

for prime in primes:
    arr = list(str(prime))
    permutations = set()

    # get all prime permutations of the prime
    while next_permutation(arr):
        x = int("".join(map(str, arr)))
        if isprime(x):
            permutations.add(x)
    
    for perm in permutations:
        diff = perm - prime
        prime3 = perm + diff
        if isprime(prime3):
예제 #3
0
#!/usr/bin/python
from sympy import isprime
from Functions.Functions import Functions
from time import clock

# http://www.mathblog.dk/project-euler-27-quadratic-formula-primes-consecutive-values/

start = clock()
highest = 0
max_a = 0
max_b = 0
primes = Functions.sieve(1000)
for a in range(-999, 1000, 2):
    for b in primes:
        for n in range(100):
            if not isprime(n**2 + a * n + b):
                count = n + 1
                if count > highest:
                    highest = count
                    max_a = a
                    max_b = b
                break

print "a={}\nb={}\nProduct={}\nCount={}\n".format(max_a, max_b, max_a * max_b,
                                                  highest)
print clock() - start