def blankSlotPrimes(n,m): d = n - m # d for digits # Create list of primes we will use primeList = pf.sieveEratosthenes(10**(n+1)) # Remove primes that are too small startIndex = 0 for i in xrange(0,len(primeList)): if primeList[i] > 10**(n-1): startIndex = i break primeList = primeList[startIndex:] # Set up set for fast prime checking primeSet = set(primeList) # Indecies for the repeated digits digitIndeces = [] for i in xrange(0,m): digitIndeces.append(range(0,d+1)) # Data structure cleverness - how we insert the repeated digits # into the number NumStruct = ['' for x in xrange(0,2*d+1)] numIndex = [ 2*x+1 for x in xrange(0,d)] repIndex = [ 2*x for x in xrange(0,d+1)] # Keep track of maximum maxPrimeCount = 0 maxPrimeStruct = ([],[]) # Go through all the numbers with the repeated digits for ni in xrange(0,10**d): # Set up the struct numStr = str(ni).zfill(d) for i in xrange(0,d): NumStruct[numIndex[i]] = numStr[i] # Find the repeated indecies with the most primes for t in itertools.product(*digitIndeces): primeCount = 0 smallestValue = -1 # Store the smallest value of the prime # Loop through actual value of repeated digits for r in xrange(0,10): numStruct = list(NumStruct) # Place in the digits according to positions, t for i in xrange(0,len(t)): numStruct[repIndex[t[i]]] += (str(r)) # Check if the number is prime num = int(''.join(numStruct)) if num in primeSet: if smallestValue < 0: smallestValue = r # Update the smallest value of the prime primeCount += 1 # Update maximum if primeCount > maxPrimeCount: maxPrimeCount = primeCount numStruct = list(NumStruct) for i in xrange(0,len(t)): numStruct[repIndex[t[i]]] += str(smallestValue) smallest = int(''.join(numStruct)) maxPrimeStruct = (list(t),list(NumStruct),smallest) return (maxPrimeCount, maxPrimeStruct)
progress = 1503 lastprime = x while x < 10**7: if pf.isPrimeFast(x): count += 1 lastprime = x if count == 10001: # print "FOUND IT" # print (x, count) return if x % progress == 0: print (lastprime,count) x += 2 # Best solution if problem == 7: primelist = pf.sieveEratosthenes(2*10**6) print primelist[10000] ##################################################################### # Problem 8 def maxprod(nums,k): prod = 1 for i in xrange(k): prod = nums[i] m = prod i = 0 mi = i while i < len(nums) - k: if i + k > len(nums): break