Find the closed form of the following sequence of integers: $a_1=x>0$, $$a_n=\left\lfloor\dfrac{(n+2)a_{n-1}-2}{n}\right\rfloor, n \ge 2$$
I calculated a few terms, and $a_1=x$, $a_2=2x-1$, $a_3=2x-6+\lfloor \frac{4x}{3}\rfloor$. However, the terms get really ugly after this. Then, I tried to find the closed form for certain values of $x$. For example, when $x=5$, I found that consecutive terms differ by $4$, $5$, $6$..., so the closed form is $a_n=\frac{n^2}{2}+\frac{5n}{2}+2$. Firstly, I'm not sure how to prove this, and secondly, this method does not always work for other values of $x$, so I'm not sure what to do next.
Thanks in advance!
I'm assuming that one only needs to consider integer values for $x$ as the succeeding terms will end up being integers. (Update: I'm wrong about only needing to assume that one needs to consider integers. It appears that if the fractional part of $x$ is greater than or equal to 1/2, then a different sequence is generated.)
One can generate sequences for several initial values and look up those sequences at https://oeis.org/. (One finds the same sequence that you found for $x=5$.) Then maybe an overall closed-form solution will become apparent.
Alternatively, one can speed up that process with software. Here I'm using Mathematica.
There certainly appears to be a consistent pattern here with one pattern for multiples of 3 and another for the remaining values.
For integer values of $x$ that are multiples of 3 the general sequence is generated by
$$a(n)=\frac{1}{24} \left(4 n (n+3) x+3 \left((-1)^n+7\right)-6 n (n+2)+8 x\right)$$
Update:
From the comment by @JoshuaWang a simplification can be made. For non-negative integer values of $k$ the following gives the sequences for $x=3k$, $x=3k+1$, and $x=3k+2$:
$$a_{3k}=\frac{7+(-1)^n}{8}+k+\frac{(3k-1)n}{2}+\frac{(k-1/2)n^2}{2}$$ $$a_{3k+1}=1+k+\frac{3kn}{2}+\frac{k n^2}{2}$$ $$a_{3k+2}=1+k+\frac{(3k+2)n}{2}+\frac{k n^2}{2}$$
2nd update: Values of $x$ where the fractional part is not zero
From trying various starting values it appears that values of $x$ where the fractional part (denoted by $\{x\}$) is less than 1/2 results in the same sequence (for $n \geq 2$) as that of the floor of $x$ ($\lfloor x \rfloor$) which is described previously.
Also, for those values of $x$ with a fractional part greater than or equal to 1/2 and less than 1 ($1/2 \leq \{x\} <1$), the same sequence results. In other words, $x=3.57$ and $x=3.999$ result in the same sequence.
Here is the evidence (rather than proof) I base that on:
We can generate a series of sequences for various starting values to see if a pattern exists similar to before:
Note that we can rewrite the sine and cosine terms as follows:
$$\cos(\frac{2n\pi}{3})=3 \left\lfloor \frac{n}{3}\right\rfloor -3 \left\lfloor \frac{n+2}{3}\right\rfloor +2$$
$$\sqrt{3}\sin(\frac{2n\pi}{3})=\frac{3}{2} \left(n-3 \left\lfloor \frac{n+1}{3}\right\rfloor \right)$$