<s>[INST] Is there a mathematical way to solve this problem? The question goes something like this:

How many different ways can you add up 2, 3, and 5 to get a sum of 12. Numbers can be repeated, and all three numbers do not have to be used for each solution. For instance, 5 + 2 + 2 is an answer, and so is 2 + 5 + 2.

The answer is 5 different ways:


*

*5 + 5 + 2 

*2 + 2 + 2 + 2 + 2 + 2 

*3 + 3 + 3 + 3 

*3 + 3 + 2 + 2 + 2 

*5 + 3 + 2 + 2


Is there some equation or formula that can be used to solve this problem, or does it have to be done manually?
 [/INST] Here's a way to enumerate all sums of $5$, $3$, and $2$ that add up to $n$,
if we do not consider the order of the terms in the sums to matter.
Let's consider just sums of $2$ and $3$ at first.
If $n > 1$, there is at least one such sum that adds up to $n$.
To find a specific sum, take the remainder of $n$ after dividing by $3$,
and treat each remainder as a separate case:
Case 0: $n = 3m$. Then the sum is simply
$$
n = 3m = \overbrace{3+3+\cdots+3}^{m\ \text{times}} 
$$
Case 1: $n = 3m + 1$, where $m \geq 1$. Then the sum is
$$
n = 3(m-1) + 2\cdot2
  = \overbrace{3+3+\cdots+3}^{m - 1\ \text{times}} + 2 + 2
$$
Case 2: $n = 3m + 2$. Then the sum is
$$
n = 3m + 2 = \overbrace{3+3+\cdots+3}^{m\ \text{times}}  + 2
$$
These are the maximum numbers of $3$s that can appear in the sum,
depending on which case applies.
Once we have found such a sum in which the term $3$ appears $k$ times,
we can substitute $2+2+2$ for $3+3$ until the number of $3$s remaining
is less than $2$. There are therefore $\lfloor k/2 \rfloor + 1$
distinct sums consisting only of $2$s and $3$s without regard to order.
If we now consider sums using $2$, $3$, and $5$ as terms,
we can convert any such sum to a sum of just $2$s and $3$s by
substituting $5=3+2$ until no $5$s remain.
Working backwards, any sum using $2$, $3$, and $5$ can be obtained
by starting with a sum consisting only of $2$s and $3$s
of the form $n = 3a + 2b$ and then replacing $3+2$ with $5$
(rearranging the order of terms as needed) up to $\min\{a,b\}$ times.
In summary to generate all possible sums of $2$, $3$, and $5$
adding up to $n$, we find an integer $k$ such that either
$n = 3k$, $n=3k+2$, or $n=3k+4$ 
(only one of these will be possible).
We use the substitution $3+3=2+2+2$ to generate a list of
$\lfloor k/2 \rfloor + 1$ sums 
of the form $n = 3a + 2b$ (including the original sum).
From each of the resulting sums,
using the substitution $3+2=5$, we generate a
list of $\min\{a,b\} + 1$ sums of $2$, $3$, and $5$.
If we do not actually do the final step above, but simply
count $\min\{a,b\} + 1$ for each sum of the form $n = 3a + 2b$,
it is possible in this way to count the number of sums without actually listing all of them.
Moreover, we can subdivide the list of sums of $2$s and $3$s into
two sublists: all the sums that have more $2$s than $3$s,
and the sums that do not.
In the first sublist, if the number of $3$s in the sums has a minimum $p$
and maximum $p+2q$, then the total number of sums generated from this
sublist of sums is $(p+q+1)(q + 1)$.
In the second sublist, if the number of $2$s in the sums has a minimum $r$
and maximum $r+3s$, then the total number of sums generated from this
sublist of sums is $\frac12(2r+3s+2)(s + 1)$.
Hence all we actually need to do is to find the minimum and maximum values
of $a$ for which $3a+2b=n$ and $0 \leq a < b$,
and the minimum and maximum values of $b$ for which
$3a+2b=n$ and $0\leq b \leq a$, determine the values $p$ and $q$
or $r$ and $s$ to plug into each of the formulas above,
and add the two results together.
</s>