def sumOfConsectutivePrimes(limit=1000000): p.genPrimesESieve(1000000, True) i, j = 1, 2 runningSum, maxPrime = p.primes[i], 0 result, longest = runningSum, 1 for i in xrange(1, len(p.primes)): j = i+1 count = 1 runningSum = p.primes[i] if runningSum >= 40: break curLongest, curMaxPrime = 2, 0 while runningSum+p.primes[j] < limit: count +=1 runningSum += p.primes[j] if p.isPrime(runningSum): curLongest = count curMaxPrime = runningSum j += 1 if curLongest >= longest: result = curMaxPrime longest = curLongest print longest, result return longest, result
def largestPandigitalPrime(): p.genPrimesESieve(7654321, True) index = len(p.primes) while index >= 1: prime = p.primes[index] if isPandigital(prime): return prime index -= 1 return None
def sumOfTruncatablePrimes(n=11): S = [] p.genPrimesESieve(1000000, True) for nth in xrange(5, len(p.primes)+1): prime = p.primes[nth] # via wiki, 83 right-truncatable primes vs 4260 left-truncatable # Test left to right prime building first if truncatablePrime(prime, True) and truncatablePrime(prime, False): S.append(prime) n -= 1 if n == 0: break return sum(S)
def firstOfFourConsecutive(): p.genPrimesESieve(1000000, True) consecutivePrimes, firstPrime = 0, 2 n = 2*3*5*7-1 while consecutivePrimes < 4: n += 1 nPrimes = nOfPrimeFactors(n)#len(DistinctPrimes(n)) if nPrimes == 4: consecutivePrimes += 1 if consecutivePrimes == 1: firstPrime = n else: consecutivePrimes = 0 return firstPrime
def golbachProvedWrong(): p.genPrimesESieve(10000, True) for n in xrange(3, p.primes[len(p.primes)], 2): if n in p.primes.values(): continue contradicted = True root = 0 nthPrime = 1 while n >= p.primes[nthPrime]: if isTwiceSquare(n-p.primes[nthPrime]): contradicted = False break nthPrime +=1 if contradicted: return n return 'Something is wrong here...'
def threePrimePermutations(): p.genPrimesESieve(10000, True) i = 1 nPrimes = len(p.primes) while i < nPrimes: prime = p.primes[i] if prime > 1000 and prime != 1487: sortedPrime = sorted(str(prime)) j = i+1 while j < nPrimes: secondPrime = p.primes[j] if sorted(str(secondPrime)) == sortedPrime: diff = secondPrime - prime testValue = secondPrime + diff if sorted(str(testValue)) == sortedPrime and testValue in p.primes.values(): return str(prime) + str(secondPrime) + str(testValue) j += 1 i += 1 return None
def main(): p.genPrimesESieve(87400) print 'Product of the coefficients for which produces the ' +\ 'longest sequence of primes.' print coefficientProducts2()