Exemplo n.º 1
0
Arquivo: 049.py Projeto: zmj/Euler
from zMath import numericPermutations
from zMath import PrimeGen
import sets


primegen = PrimeGen(10000)

primes = list()
for p in range(1001, 10001, 2):
	if primegen.isPrimeHash(p):
		primes.append(p)

permutationGroups = dict()
for num in primes:
	numSet = frozenset(str(num))
	if numSet not in permutationGroups:
		permutationGroups[numSet] = list()
	permutationGroups[numSet].append(num)

for numSet, numList in permutationGroups.items():
	if len(numList) < 3:
		del permutationGroups[numSet]


for numList in permutationGroups.itervalues():
	#print numList
	for i in range(0, len(numList)-2):
		for j in range(i+1, len(numList)-1):
			num1 = numList[i]
			num2 = numList[j]
			num3 = num2 - (num1 - num2)
Exemplo n.º 2
0
Arquivo: 046.py Projeto: zmj/Euler
from zMath import PrimeGen
from math import sqrt

maxNum = 10000
primes = PrimeGen(maxNum)
print "Primes generated"
composite = 3
while True:
	if primes.isPrimeHash(composite):
		composite += 2
		continue

	found = False
	for sq in range(1, int(sqrt(composite))):
		primeDifference = composite - 2*sq**2
		if primes.isPrimeHash(primeDifference):
			#print str(composite) + " = "+str(sq)+"^2 + " + str(primeDifference)
			found = True
			break

	if not found or composite > maxNum:
		print composite
		break
	else:
		composite += 2
Exemplo n.º 3
0
Arquivo: 050.py Projeto: zmj/Euler
from zMath import PrimeGen

maxNum = 1000000
primegen = PrimeGen(maxNum)
longestChain = 0
resultingPrime = 0
for primeIndex in range(0, len(primegen.primes)):
	chain = 0
	sum = 0
	while sum<maxNum and primeIndex+chain<len(primegen.primes):
		if primegen.isPrimeHash(sum) and chain>longestChain:
			longestChain = chain
			resultingPrime = sum

		sum += primegen.primes[primeIndex+chain]
		chain += 1

#print longestChain
print resultingPrime
		
Exemplo n.º 4
0
Arquivo: 047.py Projeto: zmj/Euler
from zMath import PrimeGen
import sets

primes = PrimeGen(1000000)
print "Primes generated"
n = 4 
current = range(1, n+1)

while True:
	allValid = True
	for num in current:
		if len(primes.distinctPrimeFactors(num)) != n:
			allValid = False
			break

	if allValid:
		break
	else:
		del current[0]
		current.append(current[-1]+1)

print current[0]