max = 200
max=max+2 ### due to the later code, it got offset by 2
P = [0]*max ### make a list of zeros, length max
P[0] = 1
P[1] = 1
print 0,":", P[0] ### print value for n = 0,1
print 1,":", P[1]
Psign = [0]*max ### make a list the same length as P, to store the signs
### apply Euler's pentagonal numbers formula
k = 1
index= k*(3*k-1)/2
while index <=max:
Psign[index] = (-1)**k
index = k*(3*k+1)/2
if index<=max:
Psign[index] = (-1)**k
k=k+1
index = k*(3*k-1)/2
for n in range(1,max+1):
n=n+1
P[n] = 0
for i in range(0,n+1):
i=i+1
P[n] = P[n] - P[n-i]*Psign[i]
print n,":",P[n]
所以我得到了这个代码,它可以回答 n 的分区数(目前最多 200 个)。但是,由于我从这里改编了用 Mathematica 编写的代码。我不太确定后面的部分。不知何故,这部分搞砸了我的限制。因此,如果我想为 25 生成分区数,我必须将我的 max 变量设置为 27。
我真的希望有人能帮我纠正这个
干杯,
亚历克斯