We're given an exercise for a programming lesson. It goes like this:
Starts with an array, ranging from $1$ to $n$. At every iteration, add $2$ neighboring numbers together. Stop when the amount of numbers in the array reaches $1$.
Here's a visual representation:
1 2 3 4 5
\/ \/ \/ \/
3 5 7 9
\/ \/ \/
8 12 16
\/ \/
20 28
\ /
48
The problem is, doing this step by step took way too much time, especially when we have to deal with $n = 2018201820182018$. So, is there a way to calculate the final number without doing the addition?
EDIT: We're allowed to do a modulus of the answer with $10^9$, and I've found a formula for calculating the final number: $(n+1) * 2^{(n-2)}$, but the latter part still gives a very large result. Are there any other formulas?