view problem50.py @ 0:0e08f4decf67

Adding files from xenon
author Dominic Cleal <dominic@computerkb.co.uk>
date Mon, 01 Dec 2008 02:44:16 +0000
parents
children fa152d695acd
line wrap: on
line source

import math

def count(i):
	c,t = 0,0
	for x in p:
		t += x
		c += 1
		if t == i:
			return c
		if t > i:
			return False

cmax = 0
imax = 0
p = [ 2 ]
i = 3
while i < 1000000:
	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)
		if not c == False and c > cmax:
			cmax = c
			imax = i
			print "New max %d with %d conseq" % (i, c)
	i += 2