# Solving a functional discrete equation.

I was to solve the following functional discrete equation (I arguing that $a_k$ is a discrete function):

$$f\left[a_{k+1}\right]-f\left[a_{k}\right]=0$$

where

$$f\left[a_{k}\right]=\sum_{i=a_{k}}^{a_{k+1}}n-\left(i+1\right)$$

and boundary conditions

\begin{cases} a_{1} & =0\\ a_{p+1} & =n \end{cases}

where $n\gt1, p\gt0 \text{ and } k=1,3,\dots,p$

Since the sum can be computed, and I've arrived to the following non-linear recursion equation:

$$\left(1-2n\right)a_{k}+\left(4n-2\right)a_{k+1}+a_{k+2}\left(a_{k+2}-2n+1\right)+a_{k}^{2}=2a_{k+1}^{2}$$

After trying several approaches, I desperately tried brute force, computing several cases to the different parameters, and, after some effort, I found this simple relationship:

$$a_k = \frac{1}{2p}\left(-p+2p\left(n+1\right)-\sqrt{p^{2}+4p\left(p+1-k\right)\left(n+1\right)n}\right)$$

which:

1. Agrees with the boundary conditions.
2. When I substitute it on the recursive equation gives a true sentence.

What I believe is enough to prove that this is a solution of the problem.

what I'm asking is if there is any method for solving this problem that can lead me to the same result without having to make this "anzatz"; the solution seems very simple, suggesting me a possible analytical method to solve the recursion equation (the solution seems the solution of a $2^º$ order algebraic equation).

-