Mercurial > hg > euler
view problem50.py @ 1:fa152d695acd
#50, start of conseq can vary
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Mon, 01 Dec 2008 03:14:35 +0000 |
parents | 0e08f4decf67 |
children | 49c96972949d |
line wrap: on
line source
import math def count(i, min): for a in range(0, len(p) - min): t = 0 for b in range(a, len(p)): t += p[b] if t == i: return b - a + 1 if t > i: break return False cmax = 0 imax = 0 p = [ 2 ] i = 3 while i < 1000: isp = True max = int(math.floor(math.sqrt(i))) for t in p[1:]: if t > max: break if i % t == 0: isp = False break if isp: p.append(i) c = count(i, cmax) if not c == False and c > cmax: cmax = c imax = i print "New max %d with %d conseq" % (i, c) i += 2