Deje $\mathbb{N} := \{0, 1, 2, ...\}$ ser el conjunto de los números naturales (i.e números enteros no negativos). Dado $N\in\mathbb{N}\backslash\{0\}$, $n\in\mathbb{N}$, y $(a_1, a_2, ..., a_N) \in\mathbb{N}^N$, vamos a $P_{N}(a_1, a_2, ..., a_N, n)$ el número de soluciones del sistema lineal Diophatine ecuación
\begin{equation}
\sum_{k=1}^N{a_kx_k} = n, \space x\in\mathbb{N}^N
\end{equation}
Tenga en cuenta que $P_{N}$ define una función de$\mathbb{N}^{N+1}$$\mathbb{N}\backslash\{0\}$.
A continuación, la siguiente fórmula recursiva se establece fácilmente por inducción en $N$ ( $N>2$ , fix $x_1\in[0, n/a_1]\cap \mathbb{N}$, y para resolver $(x_2$, ..., $x_N)\in\mathbb{N}^{N-1}$)
\begin{equation}
\begin{split}
P_1(a_1, n) = 1, \text{if %#%#% is a multiple of %#%#%, %#%#% otherwise;}\\
P_N(a_1, a_2, ..., a_N, n) = \sum_{x_1\in [0, n/a_1]\cap \mathbb{N}}P_{N-1}(a_2, ..., a_N, n - x_1a_1)\text{, if %#%#%}
\end{split}
\end{equation}
El siguiente (ingenuo) fragmento de código en Python va a resolver cualquier instancia del problema en un tiempo finito.
def diophantine_count(a, n):
"""Computes the number of nonnegative solutions (x) of the linear
Diophantine equation
a[0] * x[0] + ... a[N-1] * x[N-1] = n
Theory: For natural numbers a[0], a[2], ..., a[N - 1], n, and j,
let p(a, n, j) be the number of nonnegative solutions.
Then one has:
p(a, m, j) = sum p(a[1:], m - k * a[0], j - 1), where the sum is taken
over 0 <= k <= floor(m // a[0])
Examples
--------
>>> diophantine_count([3, 2, 1, 1], 47)
3572
>>> diophantine_count([3, 2, 1, 1], 40)
2282
"""
def p(a, m, j):
if j == 0:
return int(m == 0)
else:
return sum([p(a[1:], m - k * a[0], j - 1)
for k in xrange(1 + m // a[0])])
return p(a, n, len(a))
Ahora que tenemos el martillo, vamos a encontrar las uñas...
OK, volviendo a tu problema, tenemos $n$.
N. B: $a_1$, de acuerdo con mercio de la fuerza bruta de cálculo :)
Saludos,