from math import * #Returns all partitions of n. # #See: Jerome Kelleher and Barry O'Sullivan, Generating All Partitions: A Comparison Of Two Encodings, arXiv:0909.2331 [cs.DS], 2009-2014. def accelAsc(n): a = [0 for i in range(n + 1)] k = 1 y = n - 1 while k != 0: x = a[k - 1] + 1 k -= 1 while 2*x <= y: a[k] = x y -= x k += 1 l = k + 1 while x <= y: a[k] = x a[l] = y yield a[:k + 2] x += 1 y -= 1 a[k] = x + y y = x + y - 1 yield a[:k + 1] def isPrime(n): n=abs(int(n)) if n<2: return False if n==2: return True if not n&1: return False for x in range(3,int(n**0.5)+1, 2): if n%x==0: return False return True seq = [] idx = 0 for i in range(10): n = 3 * i prtns = list(accelAsc(n)) tmp = [0] * int(floor(n/2) + 1) for prtn in prtns: pct = 0 for k in prtn: if isPrime(k): pct += 1 tmp[pct] += 1 seq.append(tmp[idx]) idx += 1 print(seq)