Let $b(n,p)$ be the number of partitions of $n$ into pieces each of which is positive, is prime, and is less than or equal to $p$. Let $pp(k)$ be largest prime less than or equal to $k$.

$$ pp(k) = \begin{cases} k , & k \text{ prime} \\ \max (\mathrm{Primes} \cap [1,k]) , & k \text{ composite} \end{cases} $$
Since the only numbers that can be written as a partition into primes $\leq 2$ are even numbers, \begin{align*}
b(n,2) = \begin{cases} 0 , & n \text{ odd} \\
1 , & n \text{ even} \end{cases} \text{.}
\end{align*} Now suppose $p > 2$ is prime.
Then \begin{align*}
b(n,p) &= b(n - 0p,pp(p)) + b(n-1p, pp(p)) + \cdots + b \left( n- \left\lfloor \frac{n}{p} \right\rfloor p, pp(p) \right) \\
&= \sum_{k=0}^{\left\lfloor n/p \right\rfloor} b(n - k p, pp(p)) \text{.}
\end{align*}
Otherwise $p > 2$ is composite and
$$ b(n,p) = b(n,pp(p)) \text{.} $$

An implementation in Mathematica:

```
b[n_?NumericQ, 2] := If[EvenQ[n], 1, 0];
b[n_?NumericQ, p_ /; PrimeQ[p]] :=
b[n, p] = Sum[ b[n - k p, NextPrime[p, -1] ], {k, 0, Floor[n/p]}]
b[n_?NumericQ, p_ /; Not[PrimeQ[p]] ] :=
b[n, p] = b[n, NextPrime[p, -1]];
b[n_?NumericQ] := b[n, n]
```

The idiom `b[n_,m_] := b[n,m] = ...`

memoizes computed values of $b$. It causes Mathematica to store the particular values as short-circuit evaluations benefiting future recursions that require them. That is, $b(11,11) = 6$ is only ever computed by recursion once until the kernel is restarted (or you `Clear`

the assignment `b[11,11] = 6`

). The definition `b[n_] := b[n,n]`

makes a unary version of $b$ that computes the number of partitions of $n$ using primes no larger then $n$.

```
Table[{n, b[n]}, {n, 2, 20}] // TableForm
(* 2 1
3 1
4 1
5 2
6 2
7 3
8 3
9 4
10 5
11 6
12 7
13 9
14 10
15 12
16 14
17 17
18 19
19 23
20 26 *)
b[100]
(* 40899 *)
b[200]
(* 9845164 *)
```

For large arguments, we need to prevent the mild attempts to prevent infinite loops.

```
Block[{
$RecursionLimit = 5000,
$IterationLimit = 5000
},
DiscretePlot[{Log[n, b[n]]}, {n, 2, 2000}]
]
```

```
TableForm[Table[{100 k, b[100 k]}, {k, 1, 30}]]
```

$$ \begin{array}{rr}
n & b(n) \\ \hline
100 & 40\,899 \\
200 & 9\,845\,164 \\
300 & 627\,307\,270 \\
400 & 20\,075\,018\,700 \\
500 & 414\,270\,104\,287 \\
600 & 6\,267\,622\,640\,718 \\
700 & 75\,023\,235\,861\,131 \\
800 & 746\,579\,898\,675\,387 \\
900 & 6\,392\,242\,051\,193\,026 \\
1000 & 48\,278\,613\,741\,845\,757 \\
1100 & 327\,744\,293\,190\,020\,336 \\
1200 & 2\,029\,147\,863\,444\,364\,710 \\
1300 & 11\,590\,550\,282\,322\,997\,472 \\
1400 & 61\,654\,092\,345\,462\,767\,992 \\
1500 & 307\,767\,211\,680\,878\,103\,266 \\
1600 & 1\,450\,997\,588\,181\,557\,017\,431 \\
1700 & 6\,495\,951\,378\,101\,560\,661\,960 \\
1800 & 27\,743\,014\,519\,009\,825\,296\,856 \\
1900 & 113\,481\,312\,640\,973\,435\,202\,574 \\
2000 & 446\,121\,153\,521\,479\,463\,708\,832 \\
2100 & 1\,690\,633\,708\,394\,918\,231\,947\,808 \\
2200 & 6\,192\,537\,346\,397\,477\,180\,809\,944 \\
2300 & 21\,975\,198\,457\,476\,870\,147\,875\,871 \\
2400 & 75\,709\,986\,489\,697\,972\,886\,549\,803 \\
2500 & 253\,714\,665\,648\,596\,332\,053\,234\,626 \\
2600 & 828\,407\,291\,699\,814\,300\,659\,000\,601 \\
2700 & 2\,639\,436\,199\,390\,992\,422\,102\,282\,380 \\
2800 & 8\,217\,667\,977\,417\,902\,397\,061\,965\,136 \\
2900 & 25\,032\,453\,880\,409\,897\,119\,453\,395\,767 \\
3000 & 74\,692\,232\,370\,346\,735\,766\,630\,583\,120 \\
\end{array} $$

A semantically equivalent implementation of $b$ in Python (2.7) which is set up to produce the table of values shown above.

```
from numbers import Number
from sympy import isprime, prevprime
cache = dict()
def b(n, p = None):
if p == None:
p = n
if not (( isinstance(n, Number) ) and (n >= 0)):
raise TypeError('First argument to function b() must be an integer >= 0.')
if not (( isinstance(p, Number) ) and (p >= 2)):
raise TypeError('Second argument to function b() must be an integer >= 2.')
if (n, p) in cache:
return cache[(n,p)]
if p == 2:
# If n is even, return 1, else return 0.
retVal = 1 - (n % 2)
elif isprime(p):
retVal = sum(( b(n - k * p, prevprime(p) ) for k in range(0, 1 + n//p)) )
else:
retVal = b(n, prevprime(p))
cache[(n, p)] = retVal
return retVal
print( "b(100) = " + str(b(100)) )
print( "b(200) = " + str(b(200)) )
for k in range(1, 31):
print( "b(" + str(100*k) + ") = " + str(b(100*k)) )
```