# mzd/project-euler

### Subversion checkout URL

You can clone with
or
.
Fetching contributors…

Cannot retrieve contributors at this time

37 lines (31 sloc) 0.995 kB
 #!/usr/bin/python -tt import mathlib # Project Euler # Problem 50 # The prime 41, can be written as the sum of six consecutive primes: # 41 = 2 + 3 + 5 + 7 + 11 + 13 # This is the longest sum of consecutive primes that adds to a prime # below one-hundred. # # The longest sum of consecutive primes below one-thousand that adds # to a prime, contains 21 terms, and is equal to 953. # # Which prime, below one-million, can be written as the sum of the # most consecutive primes? def solve(): primes = mathlib.getPrimes(1000000) primesum = [0] s = 0 count = 0 while s < 1000000: s += primes[count] primesum.append(s) count += 1 terms = 1 for i in range(count): for j in range(i + terms, count): n = primesum[j] - primesum[i] if (j-i>terms and mathlib.isPrime(n)): terms, maxprime = j-i, n return maxprime print solve()
Something went wrong with that request. Please try again.