Is there any Algorithm to Write a Number $N$ as a Sum of $M$ Natural Numbers? I have a number $N$ (for example $N=64$). 
Is there any algorithm to find all the feasible ways for writing the number $N$ as a sum of $M$ positive numbers? 
(For example $M=16$) --- Repetition is allowed.

$n_1 + n_2 + n_3 + ... + n_{16} = 64$
      $n_i \ge 1$


You can use a recursive algorithm to iterate through the solutions, but there is an easy way to count them.
The amount of non negative solutions to 
\begin{equation}
x_1 + x_2 + \cdots + x_n = a
\end{equation}
is $a + n - 1 \choose n - 1$ or equivalently $a + n - 1 \choose a$. Since we want integer solutions,  let $y_k = x_k + 1$. Each $y_k$ is now an integer. Re writing the top equation
\begin{align}
y_1 - 1 + y_2 - 1 + \cdots + y_n - 1 &= a\\
y_1 + y_2 + \cdots + y_n &= a + n
\end{align}
which still has  $a + n - 1 \choose n - 1$ solutions. Let $a + n = N$ and $n = M$, then the equation
\begin{equation}
x_1 + x_2 + \cdots + x_M =N
\end{equation}
has $N - 1 \choose M - 1$ solutions.
