One can express the $n$-th whatever-nicci number as a linear combination of the $n$-th powers of the roots of a certain polynomial. Then the sum is just that linear combination of the sum of finite geometric series. So in a sense we get a closed-form formula. Perhaps that can be expressed as a linear combination of explicit whatever-nicci numbers.
–
André NicolasFeb 21 '12 at 6:52

In fact, we can always express the sum as a linear combination of $n$ terms in the series and a constant. For the Fibonacci numbers, something nice happens and we only need one.
–
Yuval FilmusFeb 21 '12 at 7:05

Please do not post a complete solution to the problem here. Looks like the OP wants to solve: spoj.pl/problems/TETRASUM
–
user25383Feb 21 '12 at 9:51

Upps, I hope there was nothing wrong with my answer... Why didn't the OP add a remark? (P.s. my firefox-browser does not "trust" that link. Is it ok to proceed to there? (added: I can open that site if I use "http" instead of "https"))
–
Gottfried HelmsFeb 21 '12 at 9:57

2

I see no evidence that the OP got the problem from the SPOJ site; it’s a perfectly reasonable mathematical question independent of any programming aspects.
–
Brian M. ScottFeb 22 '12 at 6:45

where $\mu_0,\mu_1,\mu_2,\mu_3$ are arbitrary initial values and $\mu_n=\mu_{n-1}+\mu_{n-2}+\mu_{n-3}+\mu_{n-4}$ for $n\ge 4$; it is formula $(39)$ in the paper. It can be proved by induction, but Waddill gives a nicer proof by summing the identities $$\mu_k+\mu_{k+1}+\mu_{k+2}=\mu_{k+2}-\mu_{k+1}$$ for $k=0,\dots,n$ to obtain $$\sum_{k=0}^n\mu_k+\left(\sum_{k=0}^n\mu_k+\mu_{n+1}-\mu_0\right)+\left(\sum_{k=0}^n\mu_i+\mu_{n+1}+\mu_{n+2}-\mu_0-\mu_1\right)=\mu_{n+4}-\mu_3$$ and then $$3\sum_{k=0}^n\mu_k+2\mu_{n+1}+\mu_{n+2}-2\mu_0-\mu_1=\mu_{n+4}-\mu_3\;,$$ which can be rearranged to yield

This can also be solved by a matrix-ansatz (and then generalized in a completely obvious way).
Example: assume a vector A containing your first four values, say
$\qquad \small A=[1,3,4,5] $ .
Next consider the transfermatrix, say T which defines the composition of the next entry by $\small 1*1 + 3*1 + 4*1 + 5*1 =13$, and simply shifts the old entries $\small [1,3,4,5] \to [3,4,5,13] $ .
The required matrix T looks like

Then we have the iteration for the computation of consecutive elements of the tetranacci-sequence simply by
$\qquad \small A_{k+1} = A_k \cdot T $
or, even better:
$\qquad \small A_k = A \cdot T^k $

To sum the consecutive entries we can simply use the sum of the powers of T:
$\qquad \small S_k = A \cdot ( T^0 + T^1 + T^2 + ... + T^{k-1}) $
and the leading part of the geometric-series for the matrix T (also known as Neumann-series) is then
$\qquad \small U_k = (T^k - I) \cdot (T-I)^{-1} $ .
Thus the sum of the first k elements of the tetranacci-sequence can be found by

$\qquad \small S_k = A \cdot U_k $

and for k=5 I get

$\qquad \small S_k = [26, 50, 94, 180] $

where 26 (=1+3+4+5+13) is the sum of the first 5 elements of the sequence.

It is obvious, how this can be generalized in two ways:

different starting values: either modify the (example) init-values in
A (or keep them symbolic)

different type of m-nacci-sequences: just increase the size of
T in the obvious way