Use FindGeneratingFunction
and SeriesCoefficient
:
FindGeneratingFunction[
{15, 15, 15, 15, 17, 17, 17, 17, 19, 19, 19, 19, 21, 21, 21, 21, 23, 23, 23, 23}, x]
(15 - 13*x^4)/((-1 + x)^2*(1 + x + x^2 + x^3))
The formula:
FullSimplify[SeriesCoefficient[%, {x, 0, n}], Element[n, Integers] && n >= 0]
(1/4)*(57 + (-1)^n + 2*n + 2*Cos[(n*Pi)/2] + 2*Sin[(n*Pi)/2])
Verification:
Table[%, {n, 0, 30}]
{15, 15, 15, 15, 17, 17, 17, 17, 19, 19, 19, 19, 21, 21, 21, 21,
23, 23, 23, 23, 25, 25, 25, 25, 27, 27, 27, 27, 29, 29, 29}