2013-04-17 14:34:39 +08:00

40 lines
623 B
Python

def mkp(x):
P = [2]
p = [2]
n = 3
while n < x:
for i in p:
if n % i == 0:
break
else:
P.append(n)
n += 2
while n > p[-1] ** 2:
p.append(P[len(p)])
return P
def get(x, y):
if x <= y:
return a[x]
return dic.get((x, y))
maxx = 5000
prime = mkp(10000)
a = [0, 0, 1, 1, 1, 2]
dic = {(4, 3):1, (4, 2):1, (5, 3):1, (5, 2):0}
n = 5
while a[-1] <= maxx:
n += 1
tmp = 0
for i in prime:
if i > n:
break
tmp += get(n - i, i)
#print n - i, i, get(n - i, i)
dic.update({(n, i):tmp})
if n in prime:
tmp += 1
a.append(tmp)
print len(a) - 1