Number of ways n can be written as sum of at least two positive integers
Let us denote the array ways after $t$ iterations of the outer loop by $w_t$. The recurrence implemented by the code is
$$
w_0(n) = \begin{cases}
1 &amp; \text{if } n = 0, \\
0 &amp; \text{if } n &gt; 0.
\end{cases} \\
w_t(n) = \begin{cases}
w_{t-1}(n) &amp; \text{if } n &lt; t, \\
w_{t-1}(n) + w_t(n-t) &amp; \text{if } n \geq t.
\end{cases}
$$
You can prove by induction that $w_t(n)$ is the number of representations of $n$ as a sum of natural numbers between $1$ and $t$ (without regard to order). (This is also the number of representations of $n$ as a sum of at most $t$ natural numbers.)

The code returns $w_{n-1}(n)$, which is the number of representations of $n$ as an arbitrary sum of natural numbers, other than the representation $n$.

As an aside, if you allow the trivial representation then you get the partition function. Using Rademacher's asymptotic formula, the partition function can be computed in time $\tilde O(\sqrt{n})$, much faster than your $\Theta(n^2)$ algorithm.