Mercurial > hg > euler
view problem50.py @ 14:49c96972949d default tip
#50 rewrite of solution
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Mon, 01 Dec 2008 19:11:55 +0000 |
parents | fa152d695acd |
children |
line wrap: on
line source
import primes def search(pmax): cur = { } max = { } s = primes.testsieve() for p in s.sieve(): if p > pmax: break if p not in cur: cur[p] = (0, 0) todel = [] for i in cur: cur[i] = (cur[i][0] + 1, cur[i][1] + p) if cur[i][1] > pmax: todel.append(i) elif s.isprime(cur[i][1]): max[i] = cur[i] for i in todel: del cur[i] retmax = None for i in max: if retmax is None or max[i][0] > retmax[0]: retmax = max[i] return retmax print "Max conseq has %d terms, totalling %d" % search(1000000)