def answer(self): for prime in PrimeChecker.primesBelow(1000000): if prime > 100000: s = str(prime) lastDigit = s[5:6] if s.count("0") == 3 and self.hasPrimeVariations(s, "0", 8) \ or s.count("1") == 3 and lastDigit != 1 and self.hasPrimeVariations(s, "1", 8) \ or s.count("2") == 3 and self.hasPrimeVariations(s, "2", 8): return int(s)
def getLongestSumOfConsecutivePrimesBelow(self, n): longestSequenceLength = 0 longestSum = 0 primes = PrimeChecker.primesBelow(n) for i in range(0, len(primes)): for j in range(i+1, len(primes)-1): primeSum = sum(primes[i:j]) if primeSum >= n: break if PrimeChecker.isPrime(primeSum) and j - i > longestSequenceLength: longestSequenceLength = j - i longestSum = primeSum return longestSequenceLength, longestSum
def test_primesBelow20ShouldBe235711131719(self): self.assertEquals([2,3,5,7,11,13,17,19], PrimeChecker.primesBelow(20))
def __init__(self, primeLimit): self.primeChecker = PrimeChecker() self.primeChecker.initPrimeFactoring() self.primes = PrimeChecker.primesBelow(primeLimit) self.primes.remove(2) self.pairs = self.buildPairs(self.primes)