Evaluate $\prod_{k=1}^{n} \sum_{i\ =1}^{k} a_i$ in $\mathcal{O}(n)$


Write a Matlab program, which takes the vector $ (a_1, \ldots, a_n)$ and outputs $ \prod_{k=1}^{n} \sum_{i\ =1}^{k} a_i$ . You are only allowed to define two variables and have to solve the problem in $ \mathcal{O}(n)$ .

I am pretty sure this is closely related to Horner’s method, but I haven’t been able to simplify the expression for small $ n$ into a form that looked like Horner.

Any help is appreciated 🙂